Inherit two base classes. : Inheritance Multiple « Class « C++






Inherit two base classes.

Inherit two base classes.
  
#include <iostream>
using namespace std;

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

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

// Inherit two base classes.
class DerivedClass : public BaseClass1, 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 classes: constructing and destructing sequenceInherit two classes: constructing and destructing sequence
3.extending two parent classes
4.Call parent constructors in multiple inheritance