Constructing and Destructing sequence for two base classes : Destructor « Class « C++






Constructing and Destructing sequence for two base classes

Constructing and Destructing sequence for two base classes
 
#include <iostream>
using namespace std;

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

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

class DerivedClass: public BaseClass1, public BaseClass2 {
public:
  DerivedClass() { cout << "Constructing DerivedClass\n"; }
  ~DerivedClass() { cout << "Destructing DerivedClass\n"; }
};

int main()
{
  DerivedClass ob;

  return 0;
}


           
         
  








Related examples in the same category

1.Derived class call its base constructorDerived class call its base constructor
2.Derived constructor uses no parametersDerived constructor uses no parameters
3.Define and use the destructorDefine and use the destructor
4.System will call the destructorSystem will call the destructor
5.Implement a destructorImplement a destructor
6.Using a constructor and destructor.Using a constructor and destructor.
7.Define destrcuctor outside the class definition