Following on from what JLBorges and MiiNiPaa said...
In short,
- public inheritance is for implementing the "is a" relationship
In other terms, it's
inheritence of interface, with or without implementation. The interface defines the behavior of the class to the outside world. By inheritenting the base classes interface, you inherit its behaviour. Hence it acts like it is an instance of the base class.
(to inherit interface without implemetation you need to override all inherited methods; or use a base class with no implementaton -- a vtable only class.)
- private inheritence is for implementing the "is-implemented-in-terms-of" relationship
This is
inheritence of implementation only. The methods of the base class are hidden so cannot be used by the outside world. So the derived class can make use of the base class functionality, but that's all.
Scott Meyers (Effective C++) remarks that there are some circumstances where private inheritence is preferable to composition, either because it simplifies the implementation or because it allows the compiler to use empty base class optimization.
I think he talks about composition rather than than aggregation as the object may be treated as a whole in the case of composition, whereas an aggregate is really a collection of cooperating objects (with distinct lifetimes.)
Andy
PS Scott Meyers : Effective C++
http://www.amazon.co.uk/Effective-Specific-Addison-Wesley-Professional-Computing/dp/0201924889