Error no matching function

I keep getting these errors and don't know how to fix it.

Bank.cpp||In constructor 'Bank::Bank()':|
Bank.cpp|5|error: no matching function for call to 'Account::Account(int)'|


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#ifndef BANK_H_INCLUDED
#define BANK_H_INCLUDED

#include <string>
#include "Account.h"


using namespace std;

class Bank{
private:
    Account savings;
    Account checking;
public:
    Bank();
    Bank(double savings_amount, double checking_amount);
    void deposit(double amount, string account);
    void withdraw(double amount, string account);
    void transfer(double amount, string account);
    void print_balance();

};

#endif // BANK_H_INCLUDED 


[/code]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include "Bank.h"

using namespace std;
Bank::Bank()
{
}
/*

Bank::Bank(double savings_amount, double checking_amount): savings(savings_amount), checking(checking_amount)
{
}

void Bank::deposit(double amount, string account)
{

}


void Bank::print_balance()
{
    cout << savings << checking;
}
*/



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <string>
#include "Bank.h"

using namespace std;

main()
{
    Bank csusb_bank(1000, 100);

    csusb_bank.deposit(50, "S");
    csusb_bank.withdraw(10, "CH");
    csusb_bank.withdraw(10, "C");
    csusb_bank.transfer(40, "S");
    csusb_bank.withdraw(150, "C");
    csusb_bank.print_balance();
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include "Account.h"

using namespace std;

Account::Account():balance(0),interest_rate(0)
{
}

Account::Account(double amount, double rate): balance(amount), interest_rate(rate)
{
}

void Account::deposit(double amount)
{
    balance += amount;
}

bool Account::withdraw(double amount)
{
    bool status;

    if(amount > balance)
    {
        balance -= 5; // penalty
        status = false;
    }
    else{
        balance -=amount;
        status = true;
    }
    return status;
}

double Account::query()
{
    return balance;
}

void Account::set_interest_rate(double rate)
{
    rate += rate;
}

double Account::get_interest_rate()
{
    return interest_rate;
}

void Account::add_interest()
{
    balance += balance * (interest_rate/100);
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#ifndef ACCOUNT_H
#define ACCOUNT_H

class Account {
private:
    double balance;
    double interest_rate; // for example, interest_rate = 6 means 6%
public:
    Account();
    Account(double amount, double rate);
    void deposit(double);
    bool withdraw(double); // returns true if there was enough money, otherwise false
    double query();
    void set_interest_rate(double rate);
    double get_interest_rate();
    void add_interest();
};

#endif // ACCOUNT_H_INCLUDED
Last edited on
The code you posted compiles fine as-is. If you are getting the error, you must be compiling different code.

Please post the actual code you're compiling.

(Perhaps you didn't save one of your files, or you have the file open in two different editors and you're looking at an outdated copy... or you have two files named the same thing and you're looking at one but compiling the other)
Last edited on
This is only the piece I of code omitted, from an earlier test.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include "Account.h"

using namespace std;
/*
main()
{
    Account savings(100, 6);

    savings.deposit(20);
    cout << savings.query() << endl;

    if (savings.withdraw(50))
        cout << "Successful withdraw.\n";
    else cout << "Not enough in the account, $5 penalty charged.\n";
    cout << savings.query() << endl;

    if (savings.withdraw(100))
        cout << "Successful withdraw.\n";
    else cout << "Not enough in the account, $5 penalty charged.\n";
    cout << savings.query() << endl;
}
*/


But as you can see that it completely commented out so that I don't declare two mains.
That's all the code I have. These are all my errors as shown

||=== Build: Debug in accountTest (compiler: GNU GCC Compiler) ===|
||In constructor 'Bank::Bank()':|
|5|error: no matching function for call to 'Account::Account(int)'|
|5|note: candidates are:|
|10|note: Account::Account(double, double)|
|10|note: candidate expects 2 arguments, 1 provided|
|9|note: Account::Account()|
|9|note: candidate expects 0 arguments, 1 provided|
|4|note: Account::Account(const Account&)|
|4|note: no known conversion for argument 1 from 'int' to 'const Account&'|
|5|error: no matching function for call to 'Account::Account(int)'|
|5|note: candidates are:|
|10|note: Account::Account(double, double)|
|10|note: candidate expects 2 arguments, 1 provided|
|9|note: Account::Account()|
|9|note: candidate expects 0 arguments, 1 provided|
|4|note: Account::Account(const Account&)|
|4|note: no known conversion for argument 1 from 'int' to 'const Account&'|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

Every file is in the same directory and only open on one editor. Did you really compile my code as is?
Last edited on
Did you really compile my code as is?


Yes. I condensed it all into 1 file for my personal convenience, but the code is the same. All I changed were the includes... and I added a dummy main since I didn't see one originally (did you add it later? -- maybe I just missed it.)


Upon closer inspection, it appears you have commented out the offending line:

1
2
// This line is commented out in your code, and it is the line that would cause the error you describe:
Bank::Bank(double savings_amount, double checking_amount): savings(savings_amount), checking(checking_amount)



'savings' and 'checking' are objects of type 'Account'. You are trying to construct them with a value passed in as a parameter, however you do not have any Account constructor that takes a single parameter.
Last edited on
I see my error here now.

That line is still commented out, but I've noticed that I did this.

1
2
3
Bank::Bank():savings(0),checking(0)
{
}


The code I provided here only had this which compiles fine.

1
2
3
Bank::Bank()
{
}


Now how can I get my first line of my bank main code to work?

This one:

Bank csusb_bank(1000, 100);


Would this do it?

1
2
3
Bank::Bank(double savings_amount, double checking_amount)
{
}
Last edited on
closed account (D80DSL3A)
I saw that too Disch, but rejected it because the error concerns Bank::Bank(), not Bank::Bank(double,double).

EDIT: I see cppnoobs reply now. It was missing code.
@cppnoob25. That's probably why you're thread went so long without a reply. No one could see the problem.
Last edited on
Sorry fun2code and Disch. I still caught my error because of what Disch told me though. Thanks for the help.
Topic archived. No new replies allowed.