No Matching Function for call to...

Mar 30, 2011 at 4:44am
Hi I am new to this forum. Every time I run my program this build message appears


error: no matching function for call to 'Accounts::Accounts(std::string&, std::string&, int&, int&, std::string&, double&)'|

in my main the call to the function:
1
2
3
4
5
6
7
8
9
while (infile >> lastname)
    {
        infile >> firstname;
        infile >> ssn;
        infile >> acct_num;
        infile >> acct_type;
        infile >> acct_balance;
        bank.addAccounts(lastname,firstname,ssn,acct_num,acct_type,acct_balance);
    }



my .h file:
mutator/setter


1
2
void addAccounts(string lastname, string firstname, int ssn,
                     int acct_num, string acct_type, double acct_balance);


my .cpp:

1
2
3
4
5
6
7
 void Bank::addAccounts(string lastname, string firstname, int ssn,
                              int acct_num, string acct_type, double acct_balance)
{
    accounts[numaccts] = Accounts(lastname,firstname,ssn,acct_num,
                                  acct_type,acct_balance);
    numaccts++;
}


Any suggestions as to why this build error keeps recurring????



Mar 30, 2011 at 4:57am
1
2
Accounts(lastname,firstname,ssn,acct_num,
                                  acct_type,acct_balance);


You don't appear to have defined a constructor taking these arguments.
Mar 30, 2011 at 5:20am
Here is my constructor that I made to take in these arguments: (it is in my Accounts. h)

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
#ifndef ACCOUNTS_H
#define ACCOUNTS_H

#include <string>

#include "Depositor.h"

using namespace std;

//Accounts class declarations
class Accounts {
    int acct_num;
    string acct_type;
    double acct_balance;
    Depositor depositor;
  public:
    //Constructors
    // Accounts default constructor

    Accounts()
    {
        acct_num = 0;
        acct_type = "";
        acct_balance = 0.00;
    }

    // Accounts constructor 2 - accepts 6 arguments:
 
     Accounts(int acctnum, string accttype, double acctbalance,
              int ssn,string lastname, string firstname)
    {
        acct_num = acctnum;
        acct_type = accttype;
        acct_balance = acctbalance;
        depositor = Depositor(ssn,lastname,firstname);
    }


This is why im confused as of why it isn't compiling. @_@ Is there more to this i should be considering?
Last edited on Mar 30, 2011 at 5:27am
Mar 30, 2011 at 6:03am
You are calling it as if it takes:

(string, string, int, int, string, double)

However your definition states it takes:
(int, string, double, int, string, string)

Order is important.
Mar 30, 2011 at 6:53am
you have overloaded the function and not provided the defination on the function

1
2
Accounts(int acctnum, string accttype, double acctbalance,
              int ssn,string lastname, string firstname)
this is wrong

1
2
Accounts(string acctnum, string accttype, int acctbalance,
              int ssn,string lastname, double firstname)
This is right

Apr 1, 2011 at 5:11am
ahhh yess... simple enough lol. thank you so much
Topic archived. No new replies allowed.