14.5. Multiple Inclusion (Pattern 2)

Multiple inclusion means that derived classes contain more than one instance of the same base class. This is not possible for a direct base class (direct bases must be distinct), but it is possible for some of the direct bases to derive from a common base. Figure 14.5 illustrates an OMT diagram with multiple inclusion base classes. Since both Derived1 and Derived2 have Base1 as their direct base, a D1_D2 object includes two instances of a Base1 part. When multiple inclusion occurs, there is always a potential for ambiguity. Any access to Base1's members from a D1_D2 object must be qualified. Which Base1 object—Derived1's Base1 or Derived2's Base1?

Figure 14.5. Multiple inheritance with multiple inclusion

Get Navigating C++ and Object-Oriented Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.