windywizrd
asked on
inheritance Q.
Hi Everyone,
I have a question in reference to inheritance. I understand what constructors and destructors are for and what they do, but why cant the constructors/destructors be inherited with the public and (if any) protected members?
Thanx
Windy
I have a question in reference to inheritance. I understand what constructors and destructors are for and what they do, but why cant the constructors/destructors be inherited with the public and (if any) protected members?
Thanx
Windy
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
class Base
{
int BaseInt;
public:
Base(int i) : BaseInt(i) {} ;
};
class Derived : public Base
{
int DerivedInt;
public:
Derived(int BI,int DI) : Base(BI),DerivedInt(DI) {};
};
As you can see the derived class calls the base class's constructor to perform the initialization of the BaseInt member, but then it has its own initialization (of DerivedInt) to do.