//Example showing virtual base class inheritance

| |


#include <iostream.h>
class Base
{ public:
  virtual void print() const = 0; // pure virtual
};
class DerivedOne : virtual public Base
{
public:
  void print() const
  {
                 cout << "DerivedOne\n";
  }
class DerivedTwo : virtual public Base
{
public:
void print() const
  {
                 cout << "DerivedTwo\n";
  }
class Multiple : public DerivedOne, DerivedTwo
{
public:
void print() const
  {
                 DerivedTwo::print();
  }
};
int main()
{
  Multiple both;
  DerivedOne one;
  DerivedTwo two;
  Base *array[ 3 ];
  array[ 0 ] = &both;
  array[ 1 ] = &one;
  array[ 2 ] = &two;
  for ( int i = 0; i < 3; i++ )
  array[ i ] -> print();
  return 0;
} // end main
<