Inherit base class twice : derived class « Class « C++ Tutorial






#include <iostream>
using namespace std;

class base {
public:
  int i;
};

class derived1 :  public base {
public:
  int j;
};

class derived2 : public base {
public:
  int k;
};

class derived3 : public derived1, public derived2 {
public:
  int sum;
};

int main()
{
  derived3 ob;

  ob.derived1::i = 10; // scope resolved, use derived1's i

  return 0;
}








9.18.derived class
9.18.1.Add a constructor to derived class
9.18.2.Call base's constructor and destructor from derived class
9.18.3.Access member of base and use member of derived class
9.18.4.Overriding a base class method in a derived class
9.18.5.Hiding methods
9.18.6.Calling base method from overridden method.
9.18.7.Using virtual methods
9.18.8.Inherit base class twice
9.18.9.dynamic_cast: Cast from Derived * to Base *