C++ Virtual base classes

Description

C++ Virtual base classes

class Parent//from   w ww  . j  a  v a2  s  . c  o  m
{
   protected:
   int basedata;
};
class Child1 : virtual public Parent   // shares copy of Parent
{ };
class Child2 : virtual public Parent   // shares copy of Parent
{ };
class Grandchild : public Child1, public Child2
{
   public:
   int getdata()
   { return basedata; }    // OK: only one copy of Parent
};



PreviousNext

Related