I have a multi file program that uses classes and inheritance. I have one that is stumping me. The error is: 1>c:\users\kevin kennedy\documents\visual studio 2010\projects\lab 3\lab 3\savingsaccount.cpp(11): error C2512: 'BankAccount' : no appropriate default constructor available
I am using Visual Basic 2010 and I am lost, because this error shows up in savingsAccout.h and checkingAccount.h files.
I know the formatting may need some work but I need the fix to error. I have searched the pages here and tried a lot of different things, but I can not get rid of this error.
The default constructor is the constructor that takes no parameters, and it is special because it is called when an object is declared but is not initialized with any arguments.
Edit: On and also add BankAccount(); to bankaccount.h
and...
BankAccount.cpp - depositMoney method should return type double. It's void now.
and BankAccount.h prototype of depositMoney needs to be double as well.
Your getting the error because every class you derive rom bankaccount attempts to instantiate bankaccount using a default constructor which doesn't exist.
> You need a default constructor.
no, you don't need it.
> attempts to instantiate bankaccount using a default constructor which doesn't exist.
yes, that's the cause of the error.
however, instead of adding a default constructor you may simply call one that already exists.
I understand what ne555 was saying about not needing the default constructor, but using it was simple and no matter what I tried I could not get another constructor to be called......maybe I am overlooking the obvious.
Thanks rcast your suggestions resolved the current errors, however I have 2 more errors now.
They are:
1>CheckingAccount.obj : error LNK2019: unresolved external symbol "public: __thiscall BankAccount::BankAccount(void)" (??0BankAccount@@QAE@XZ) referenced in function "public: __thiscall CheckingAccount::CheckingAccount(void)" (??0CheckingAccount@@QAE@XZ)
1>SavingsAccount.obj : error LNK2001: unresolved external symbol "public: __thiscall BankAccount::BankAccount(void)" (??0BankAccount@@QAE@XZ)
Are these referring to the BankAccout::BankAccount(void) in the BankAccount.ccp file? That is the only place I can find them.
Let me know if you need me to post any coding I have know.
OK I think I got those 2 errors and now I have one:
1>c:\users\kevin kennedy\documents\visual studio 2010\projects\lab 3.3\lab 3.3\checkingaccount.cpp(26): error C4716: 'CheckingAccount::withdrawMoney' : must return a value
The error is an excellent description of what is going on. Line 114 doesn't return a bool but is declared to.
Also, it's simple to call non default constructor in base class via derived classes initializer list.
See:
1 2 3 4 5 6 7 8 9 10 11
class CheckingAccount: public BankAccount //inherits base class
{
public:
int num = 1234;
double amount = 12.00;
bool display =true;
CheckingAccount() : BankAccount(num, amount, display) {}
}
I understand your post and have tried several variations of this but they like to create more errors than they fix. I will try again and post the results.