Link to home
Start Free TrialLog in
Avatar of windywizrd
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
ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nietod
nietod

for example,

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.