4.3.4 Multiple interface inheritance

The interfaces found in this chapter descend directly from one or zero other interfaces. Multiple interface inheritance involves descending from multiple interfaces, and is somewhat more involved to implement. This feature is useful as it allows for greater design expressiveness—an interface can mandate that classes implementing it also implement a host of other related interfaces.

With single interface inheritance, no matter how many ancestor interfaces an interface has, classes only have to provide one dispatch table in order to successfully implement it. Scriptable, which descends directly from Fundamental, provides only one dispatch table type, Scriptable_DispatchTable_t (which is shown in Listing 4.5). Such dispatch tables also work for Fundamental (whose dispatch table type appears in Listing 4.1), because the members of Fundamental_DispatchTable_t appear before the new members introduced in Scriptable_DispatchTable_t.

With multiple interface inheritance, things are more involved. The approach taken by Stroustrup (1999) is to mandate that classes that implement interfaces that descend from multiple interfaces provide multiple dispatch tables. If interface Z descends from both X and Y, two dispatch tables would have to be provided, one containing the members from the dispatch tables of X and Z, and the other containing the members of Y and Z. Had support for multiple interface inheritance been supported, Fundamental::SwitchInterface() would use different dispatch tables depending on which interface was sought.