Hi guys, Sorry to ask a question as my first post. I'm totally new with c++ and I couldn't understand much about vectors.

case 1:
                        {
                        cout<<"Enter [S]avings Account , [C]hecking Account,[G]eneral Account"<<endl;
                        cin>>selection;
                        if ((selection == 'G') || (selection == 'g'))
                        {
                          
                         acc.push_back(newAccount);
                         cout<<"New account added"<<flush<<endl;
                         break;
                         }//end if
                         else if ((selection == 'C') || (selection =='c'))
                         {
                              checkingAccount newCheckingAcc(inType2);

                              checking.push_back(newCheckingAcc);
                              cout<<"New checking Account added"<<flush<<endl;
                                 
                         }//end else if
                         else if ((selection == 'S') || (selection == 's'))
                         {
                              savingsAccount newSavingsAcc(inType1);
                                
                              savings.push_back(newSavingsAcc);
                              cout<<"New savings account added"<<flush<<endl;
                        }//end else if
                        
                        
                        }//end case 1
account(string inType)
             {        
                      
                      _strdate(dateOpened);
                      accountNumber =  accountNumber+1;
                      accountBalance = 0.0;
                      type = inType;
                      

             };

the problem is this

class checkingAccount : public account
             {
                   public:
                   checkingAccount(string inType);
                   
                   int minBalance;
                   public:
                          bool checkingAccount:: styleChecker(int inMinBalance);
                   };
                   
                   checkingAccount::checkingAccount(string inType){};

I get the error:
In constructor `checkingAccount::checkingAccount(std::string)':
no matching function for call to `account::account()'

please help.

regards,
Irwin

Recommended Answers

All 9 Replies

did you included the header ( .h ) in the .cpp file?

did you included the header ( .h ) in the .cpp file?

wasn't taught to have one. What the lecturer taught was having everything in one .cpp file which I thought was messy.

could you post you're entire code, i think that that is the problem

From what I can tell from the error your account class has no default constructor. When you declare a constructor for a class, the compiler expects you to supply all constructors, including the default constructor.

checkingaccount inherits from account, which means it will first contruct an account object and then a checkingacount object. It calls the account::account() function, which appears to be missing.

What it is telling you is it can't find a matching function to construct the base class 'account'.

If there is not one, change your checkingAccount constructor to call the correct account constructor...

checkingAccount::checkingAccount(string inType)
:account(inType)
{
};

it says here : no matching function for call to `account::account()'

What it is telling you is it can't find a matching function to construct the base class 'account'.

If there is not one, change your checkingAccount constructor to call the correct account constructor...

checkingAccount::checkingAccount(string inType)
:account(inType)
{
};

after I did this, another error came out.
redefinition of `savingsAccount::savingsAccount(std::string)'

if i remove

savingsAccount::savingsAccount(string inType):account(inType){}

and insert

class checkingAccount : public account
             {
                   public:
                   checkingAccount(string inType):account(inType){};
                 
                   
                   int minBalance;
                   public:
                          bool checkingAccount:: styleChecker(int inMinBalance);
                   };

it now compiles properly!

it's silly of me for doing this as I read through some code samples on the internet and followed blindly.

Sorry again as I have another question to ask. How do I exactly select an element from the vector to successfully make a withdrawal(accountBalance - withdrawal)

case 3:
                        {
                         cout<<"Deposit"<<endl;
                         cout<<"======="<<endl;
                         cout<<"Please enter ammount to deposit : "<<flush;
                         cin>>ammount;
                         double temp2;
                         account newAccount(inType1);
                         newAccount.makeDeposit(ammount);
                         acc.push_back(newAccount);
                         temp = "+" + ss.str();
                         transactions.push_back(temp);
                         cout<<"Deposit successful"<<endl;
                         cout<<"New balance :"<<newAccount.getBalance()<<endl;
                         }//end case 3

I've read on the internet about a function called replace() but I certainly have no idea on how to implement it here. Should I copy the target element then deleting it and replace with a new one?

I don't think it is doing what you think it is.

account newAccount(inType1);
                         newAccount.makeDeposit(ammount);
                         acc.push_back(newAccount);

Here you are creating & storing a new account everytime you make a deposit?

What you should be doing is asking for the account to use after presenting a list from the vector.

1 Savings
2 Checking
3 Credit 1

Then use the selection as the index into the acc vector to get the correct account to manipulate...

acc[iSel].makeDeposit(amount);

cout<<"New balance :"<<acc[iSel]..getBalance()<<endl;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.