next up previous
Next: 2.1.0.2 Eiffel. Up: 2.1 Background : Multiple Previous: 2.1 Background : Multiple

2.1.0.1 C++.

C++ views multiple inheritance as replicated single inheritance. That is, a child class inherits every field/method of every parent class, unless the field/method is overridden by the child. In case more than one parent defines the same field/method, the child uses the scope-resolution operator to disambiguate the reference. The problem of repeated inheritance [27] of a field/method arises when the parents share a common ancestor. In C++, the fields in a child instance due to a common ancestor are either all shared (virtual) or all duplicated. This approach has two serious drawbacks in practice: (1) the ``all or none'' granularity in choosing to share or to duplicate fields of a common ancestor, and (2) the place where this choice is made [25,31]. Another consequence of the C++ decision is that several natural implementations, such as the code for the Tree data structure using leftmost-child-right-sibling form given below, are deemed illegal.

       class Cell :  public Link {  ... };
       class Tree :  public Cell, public Link { ... };

However, the corrected version, given in Chapter 13 of [10], requires ``unreasonable'' amount of code duplication that an OOPL is fighting hard to minimize.

       class Link {  ...code... };
       class Cell {  ...ditto + new code... };
       class Tree :  public Cell, public Link { ... };

To paraphrase S. Tucker Taft's posting to comp.lang.ada: The C++ mechanism for multiple inheritance has the worst of both the worlds: a language made more complex by the addition of linguistic multiple inheritance, and an application made more difficult by the lack of appropriate building blocks for solving the problem the ``right'' way.


next up previous
Next: 2.1.0.2 Eiffel. Up: 2.1 Background : Multiple Previous: 2.1 Background : Multiple
T. K. Prasad