hi!
There is a base class in my program from which I have built a subclass.
As you can see, I have defined 2 constructors for my base class "Account".
Code:
class Account
{
public:
int account_number;
int Deposit;
Account(int number, int money): account_number(number) , Deposit(money) {}
Account(int number)
{
account_number=number;
Deposit=0;
}
}
Then There is my subclass defined as:
class ShortTerm: public Account
I've got 2 questions here.
first, isn't it true that when the attributes"account_number" and "Deposit" have been declared in my base class, the subclass is prone to know them? so i don't have to declare them in the subclass once more? and if I do, don't they represent some other new attributes with the scope ShortTerm( for instance-> ShortTerm:: Deposit ) which coincidently have the same name as the attributes of the base class?
if all what I've written above is true, then why can't I set Deposit and account_number in the base class constructor?
I've tried this:
Code:
ShortTerm(int number, int money): account_number(number) , Deposit(money){
interest=12;
}
//interest is a new attribute declared in the subclass ShortTerm
it draws a line under Deposit and account_number with the following error:
"Deposit" is not a non static data member or base class of class ShortTerm.
now, my second question:
how can I call a chain of constructors?
having confronted the error mentioned above, I came up with the idea of calling the constructor of the base class in the constructor of the subclass. so that by this method, I may succeed to set the values of Deposit and account_number.
By the way, is it necessary to do so?