944,052 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 459
  • C++ RSS
Nov 2nd, 2009
0

problems with vectors

Expand Post »
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.

C++ Syntax (Toggle Plain Text)
  1. case 1:
  2. {
  3. cout<<"Enter [S]avings Account , [C]hecking Account,[G]eneral Account"<<endl;
  4. cin>>selection;
  5. if ((selection == 'G') || (selection == 'g'))
  6. {
  7.  
  8. acc.push_back(newAccount);
  9. cout<<"New account added"<<flush<<endl;
  10. break;
  11. }//end if
  12. else if ((selection == 'C') || (selection =='c'))
  13. {
  14. checkingAccount newCheckingAcc(inType2);
  15.  
  16. checking.push_back(newCheckingAcc);
  17. cout<<"New checking Account added"<<flush<<endl;
  18.  
  19. }//end else if
  20. else if ((selection == 'S') || (selection == 's'))
  21. {
  22. savingsAccount newSavingsAcc(inType1);
  23.  
  24. savings.push_back(newSavingsAcc);
  25. cout<<"New savings account added"<<flush<<endl;
  26. }//end else if
  27.  
  28.  
  29. }//end case 1

C++ Syntax (Toggle Plain Text)
  1. account(string inType)
  2. {
  3.  
  4. _strdate(dateOpened);
  5. accountNumber = accountNumber+1;
  6. accountBalance = 0.0;
  7. type = inType;
  8.  
  9.  
  10. };

the problem is this
C++ Syntax (Toggle Plain Text)
  1. class checkingAccount : public account
  2. {
  3. public:
  4. checkingAccount(string inType);
  5.  
  6. int minBalance;
  7. public:
  8. bool checkingAccount:: styleChecker(int inMinBalance);
  9. };
  10.  
  11. 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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
guguman is offline Offline
5 posts
since Nov 2009
Nov 2nd, 2009
0
Re: problems with vectors
did you included the header ( .h ) in the .cpp file?
Reputation Points: 10
Solved Threads: 2
Newbie Poster
Cosmin871 is offline Offline
23 posts
since Sep 2009
Nov 2nd, 2009
0
Re: problems with vectors
Click to Expand / Collapse  Quote originally posted by Cosmin871 ...
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
guguman is offline Offline
5 posts
since Nov 2009
Nov 2nd, 2009
0
Re: problems with vectors
could you post you're entire code, i think that that is the problem
Reputation Points: 10
Solved Threads: 2
Newbie Poster
Cosmin871 is offline Offline
23 posts
since Sep 2009
Nov 2nd, 2009
0
Re: problems with vectors
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.
Last edited by BeyondTheEye; Nov 2nd, 2009 at 5:39 pm.
Reputation Points: 12
Solved Threads: 10
Junior Poster in Training
BeyondTheEye is offline Offline
63 posts
since Sep 2008
Nov 2nd, 2009
0
Re: problems with vectors
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...

C++ Syntax (Toggle Plain Text)
  1.  
  2. checkingAccount::checkingAccount(string inType)
  3. :account(inType)
  4. {
  5. };
SVR
Reputation Points: 10
Solved Threads: 4
Light Poster
SVR is offline Offline
44 posts
since May 2008
Nov 2nd, 2009
0
Re: problems with vectors
it says here : no matching function for call to `account::account()'
Last edited by guguman; Nov 2nd, 2009 at 5:47 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
guguman is offline Offline
5 posts
since Nov 2009
Nov 2nd, 2009
0
Re: problems with vectors
Click to Expand / Collapse  Quote originally posted by SVR ...
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...

C++ Syntax (Toggle Plain Text)
  1.  
  2. checkingAccount::checkingAccount(string inType)
  3. :account(inType)
  4. {
  5. };
after I did this, another error came out.
redefinition of `savingsAccount::savingsAccount(std::string)'

if i remove
C++ Syntax (Toggle Plain Text)
  1. 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.
Last edited by guguman; Nov 2nd, 2009 at 5:54 pm. Reason: more details
Reputation Points: 10
Solved Threads: 0
Newbie Poster
guguman is offline Offline
5 posts
since Nov 2009
Nov 2nd, 2009
0
Re: problems with vectors
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)

C++ Syntax (Toggle Plain Text)
  1. case 3:
  2. {
  3. cout<<"Deposit"<<endl;
  4. cout<<"======="<<endl;
  5. cout<<"Please enter ammount to deposit : "<<flush;
  6. cin>>ammount;
  7. double temp2;
  8. account newAccount(inType1);
  9. newAccount.makeDeposit(ammount);
  10. acc.push_back(newAccount);
  11. temp = "+" + ss.str();
  12. transactions.push_back(temp);
  13. cout<<"Deposit successful"<<endl;
  14. cout<<"New balance :"<<newAccount.getBalance()<<endl;
  15. }//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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
guguman is offline Offline
5 posts
since Nov 2009
Nov 3rd, 2009
0
Re: problems with vectors
I don't think it is doing what you think it is.

C++ Syntax (Toggle Plain Text)
  1. account newAccount(inType1);
  2. newAccount.makeDeposit(ammount);
  3. 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;
SVR
Reputation Points: 10
Solved Threads: 4
Light Poster
SVR is offline Offline
44 posts
since May 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Get Dialog hWnd
Next Thread in C++ Forum Timeline: Structures





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC