Exercises in this lecture   Go to the notes, in which this exercise belongs -- Keyboard shortcut: 'u'   Alphabetic index   Course home   

Exercise solution:
Ignoring constructors in virtual base class


Please read section 21.3.5.1 page 634 in The C++ Prog. Lang. (4. edition) for clarification. See also the comments of the two programs referred in the execercise text.

Remember that a constructor in a virtual base must be called exactly once. Which of class B or C should control the activation of the constructor in A?

The answer is that this must be decided by the most derived base, in our case D. Therefore class D directly controls (in the initialization list of D) which A constructor to activate for the D-object.