14.1. Why Use Multiple Inheritance?

No doubt about it, multiple inheritance is controversial. Arguments abound concerning its use, overhead, overuse, and potential for ambiguities. In fact, workarounds that avoid multiple inheritance are possible. In this chapter, however, our goal is to explore multiple inheritance in C++.

Dynamic Classification

Suppose an athlete plays baseball and football. If he's good enough, he can play baseball in the major leagues and football in the NFL. Since this person plays both sports (and makes the big bucks, too), it's easy to model a multisport player as shown in Figure 14.1.

Figure 14.1. MultiSport player abstraction

In this OMT diagram, MultiSportPlayer derives from both BaseballPlayer and FootballPlayer.

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.