Inherit two classes: constructing and destructing sequence : Inheritance Multiple « Class « C++






Inherit two classes: constructing and destructing sequence

Inherit two classes: constructing and destructing sequence
  

#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 BaseClass2aseClass1, public BaseClass2 {
public:
  DerivedClass() { 
     cout << "Constructing DerivedClass\n"; 
  }
  ~DerivedClass() { 
     cout << "Destructing DerivedClass\n"; 
  }
};

int main()
{
  DerivedClass object;

  return 0;
}


           
         
    
  








Related examples in the same category

1.Directly inherit two base classes.Directly inherit two base classes.
2.Inherit two base classes.Inherit two base classes.
3.extending two parent classes
4.Call parent constructors in multiple inheritance