problems with vectors

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2009
Posts: 5
Reputation: guguman is an unknown quantity at this point 
Solved Threads: 0
guguman guguman is offline Offline
Newbie Poster

problems with vectors

 
0
  #1
27 Days Ago
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.

  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

  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
  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
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 13
Reputation: Cosmin871 is an unknown quantity at this point 
Solved Threads: 0
Cosmin871 Cosmin871 is offline Offline
Newbie Poster
 
0
  #2
27 Days Ago
did you included the header ( .h ) in the .cpp file?
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 5
Reputation: guguman is an unknown quantity at this point 
Solved Threads: 0
guguman guguman is offline Offline
Newbie Poster
 
0
  #3
27 Days Ago
Originally Posted by Cosmin871 View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 13
Reputation: Cosmin871 is an unknown quantity at this point 
Solved Threads: 0
Cosmin871 Cosmin871 is offline Offline
Newbie Poster
 
0
  #4
27 Days Ago
could you post you're entire code, i think that that is the problem
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 55
Reputation: BeyondTheEye is an unknown quantity at this point 
Solved Threads: 9
BeyondTheEye BeyondTheEye is offline Offline
Junior Poster in Training
 
0
  #5
27 Days Ago
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; 27 Days Ago at 5:39 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 33
Reputation: SVR is an unknown quantity at this point 
Solved Threads: 4
SVR SVR is offline Offline
Light Poster
 
0
  #6
27 Days Ago
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...

  1.  
  2. checkingAccount::checkingAccount(string inType)
  3. :account(inType)
  4. {
  5. };
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 5
Reputation: guguman is an unknown quantity at this point 
Solved Threads: 0
guguman guguman is offline Offline
Newbie Poster
 
0
  #7
27 Days Ago
it says here : no matching function for call to `account::account()'
Last edited by guguman; 27 Days Ago at 5:47 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 5
Reputation: guguman is an unknown quantity at this point 
Solved Threads: 0
guguman guguman is offline Offline
Newbie Poster
 
0
  #8
27 Days Ago
Originally Posted by SVR View Post
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...

  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
  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; 27 Days Ago at 5:54 pm. Reason: more details
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 5
Reputation: guguman is an unknown quantity at this point 
Solved Threads: 0
guguman guguman is offline Offline
Newbie Poster
 
0
  #9
27 Days Ago
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)

  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?
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 33
Reputation: SVR is an unknown quantity at this point 
Solved Threads: 4
SVR SVR is offline Offline
Light Poster
 
0
  #10
27 Days Ago
I don't think it is doing what you think it is.

  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;
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC