Item 29
Public inheritance means “is-a”. Everything that applies to base classed must also applu to derived classes, because derived class object is a base class object.
Item 30
1. Names in derived classes hide names in base classes. Under public inheritance, this is never desirable.
2. To make hidden names visible again, employ using
declarations or forwarding functions.
Item 31
1. Inheritance of interface is different from inheritance of implementation. Under public inheritance, derived classes inherit base class interfaces.
2. Pure virtual functions specify inheritance of interface only.
3. Simple (impure) virtual functions specify inheritance of interface plus inheritance of a default implementation.
4. Non-virtual functions specify inheritance of interface plus inheritance of a mandatory implementation.
Item 32
1. Alternatives to virtual functions include the NVI idiom and various forms of the Strategy design pattern. The NVI idiom is itself an example of the Template Method design pattern.
2. A disadvantage of moving functionality from a member function to a function outside the class is that the non-member function lacks access to the class’s non-public members.
3. tr1::function
objects act like generalized function pointers. Such objects support all callable entities compatible with a given target signature.
Item 33
Never redefine an inherited non-virtual function.
Item 34
Never redefine an inherited default parameter value, because default parameter values are statically bound, while virtual functions–the only functions you should be overriding–are dynamically bound.
Item 35
1. Composition has meanings completely different from that of public inheritance.
2. In the application domain, composition means has-a. In the implementation domain, it means is-implemented-in-terms-of.
Item 36
1. Private inheritance means is-implemented-in-terms of. It’s usually inferior to composition, but it makes sense when a derived class needs access to protected base class members or needs to redefine inherited virtual functions.
2. Unlike composition, private inheritance can enable the empty base optimization. This can be important for library developers who strive to minimize object sizes.
Item 37
1. Multiple inheritance is more complex than single inheritance. It can lead to new ambiguity issues and to the need for virtual inheritance.
2. Virtual inheritance imposes costs in size, speed, and complexity of initialization and assignment. It’s most practical when virtual base classes have no data.
3. Multiple inheritance does have legitimate uses. One scenario involves combining public inheritance from an Interface class with private inheritance from a class that helps with implementation.