| | |
problems with vectors
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2009
Posts: 5
Reputation:
Solved Threads: 0
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.
the problem is this
I get the error:
In constructor `checkingAccount::checkingAccount(std::string)':
no matching function for call to `account::account()'
please help.
regards,
Irwin
C++ Syntax (Toggle Plain Text)
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
C++ Syntax (Toggle Plain Text)
account(string inType) { _strdate(dateOpened); accountNumber = accountNumber+1; accountBalance = 0.0; type = inType; };
the problem is this
C++ Syntax (Toggle Plain Text)
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
•
•
Join Date: Sep 2008
Posts: 55
Reputation:
Solved Threads: 9
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.
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.
•
•
Join Date: May 2008
Posts: 33
Reputation:
Solved Threads: 4
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...
If there is not one, change your checkingAccount constructor to call the correct account constructor...
C++ Syntax (Toggle Plain Text)
checkingAccount::checkingAccount(string inType) :account(inType) { };
•
•
Join Date: Nov 2009
Posts: 5
Reputation:
Solved Threads: 0
0
#8 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...
C++ Syntax (Toggle Plain Text)
checkingAccount::checkingAccount(string inType) :account(inType) { };
redefinition of `savingsAccount::savingsAccount(std::string)'
if i remove
C++ Syntax (Toggle Plain Text)
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'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
•
•
Join Date: Nov 2009
Posts: 5
Reputation:
Solved Threads: 0
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)
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?
C++ Syntax (Toggle Plain Text)
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?
•
•
Join Date: May 2008
Posts: 33
Reputation:
Solved Threads: 4
0
#10 27 Days Ago
I don't think it is doing what you think it is.
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;
C++ Syntax (Toggle Plain Text)
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;
![]() |
Similar Threads
- If i use an illegal copy of windows,will it cause problems? (Windows NT / 2000 / XP)
- Vectors and Inheritance (C++)
- Alphabetically Order Vectors Elements (Java)
- Internet explorer problems (Web Browsers)
- Connection Problems (Networking Hardware Configuration)
- Pop up ads (Web Browsers)
- No time... bitch load of problems (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: Get Dialog hWnd
- Next Thread: Structures
| Thread Tools | Search this Thread |
api array arrays based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion convert count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





