Lecture 5 - Slide 20 : 40
Shared base class: Virtual bases

It is also possible for B and C to to share their A parts in a D-object - virtual bases

To see this image you must download and install the SVG plugin from Adobe.In Firefox please consultthis page.

Per default you get replicated base classes in C++

virtual-1.cc
Illustration of shared, virtual, base class A.
virtual-1-output
Program output.

Every base class of a given name that is specified to be virtual will be represented by a single object of that class, (§21.3.5, 4ed)

A constructor of a virtual base must be called exactly once - see the exercise for additional details

Go to exercise
Ignoring constructors in virtual base class
virtual-problem.cc
Ignoring constructor in virtual base class.
virtual-problem-variant.cc
Forcing use of a constructor in a virtual base class.