Virtual base classes - C++ Class

C++ examples for Class:Virtual Function

Description

Virtual base classes

class Parent
{
   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
};

Related Tutorials