Call parent constructors in multiple inheritance : Inheritance Multiple « Class « C++






Call parent constructors in multiple inheritance

  
#include <iostream>
using namespace std;
class One 
{
 public:
  One(void) { cout << "Constructor for One\n"; };
  ~One(void) { cout << "Destructor for One\n"; };
};

class Two 
{
 public:
  Two(void) { cout << "Constructor for Two\n"; };
  ~Two(void) { cout << "Destructor for Two\n"; };
};

class Three 
{
 public:
  Three(void) { cout << "Constructor for Three\n"; };
  ~Three(void) { cout << "Destructor for Three\n"; };
};


class Derived: public One, public Two, public Three 
{
 public:
   Derived(void) : One(), Two(), Three() 
   { cout << "Derived constructor called\n"; };
   ~Derived(void) 
   { cout << "Derived destructor called\n"; };
};

int main(void)
{
   Derived my_class;
}
  
    
  








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.Inherit two classes: constructing and destructing sequenceInherit two classes: constructing and destructing sequence
4.extending two parent classes