Compilation Errors Produced When Ambiguity Arises in Diamond Inheritance

Figure 21.13 demonstrates the ambiguity that can occur in diamond inheritance. Class Base (lines 8–12) contains pure virtual function print (line 11). Classes DerivedOne (lines 15–23) and DerivedTwo (lines 26–34) each publicly inherit from Base and override function print. Class DerivedOne and class DerivedTwo each contain a base-class subobject—i.e., the members of class Base in this example.

 1   // Fig. 21.13: fig21_13.cpp 2   // Attempting to polymorphically call a function that is 3   // multiply inherited from two base classes. 4   #include <iostream> 5   using namespace std; 6  7   // class Base definition 8   class Base 9   {10   

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.