Constructing and Destructing sequence for three level inheritance : Constructor « Class « C++






Constructing and Destructing sequence for three level inheritance

  
#include <iostream>
using namespace std;

class BaseClass {
public:
  BaseClass() { 
     cout << "Constructing base\n"; 
  }
  ~BaseClass() { 
      cout << "Destructing base\n"; 
  }
};

class DerivedClass1 : public BaseClass {
public:
  DerivedClass1() { 
     cout << "Constructing DerivedClass1\n"; 
  }
  ~DerivedClass1() { 
      cout << "Destructing DerivedClass1\n"; 
  }
};

class DerivedClass2: public DerivedClass1 {
public:
  DerivedClass2() { 
     cout << "Constructing DerivedClass2\n"; 
  }
  ~DerivedClass2() { 
     cout << "Destructing DerivedClass2\n"; 
  }
};

int main()
{
  DerivedClass2 ob;

  return 0;
}



           
         
    
  








Related examples in the same category

1.Parameterized ConstructorsParameterized Constructors
2.string type constructorstring type constructor
3.Use constructor to init member variablesUse constructor to init member variables
4.Use Double value as the constructor parameterUse Double value as the constructor parameter
5.Constructor: different parameter typeConstructor: different parameter type
6.Use automatic conversions to assign new valuesUse automatic conversions to assign new values
7.Call constructor from base classCall constructor from base class
8.Constructor with 2 parametersConstructor with 2 parameters
9.Define constructor outside a class definition
10.overloading class constructors
11.Constructor with parameter value checking