The statement is taken from FAQ [24.2]. What about non-virtual
functions? Can they be overriden? I still don't see a good
justification to prefer private inheritance over composition. In
fact, I have never seen it in a commercial code. If someone did,
please share the use-case and decisions behind it.
Thanks
Private inheritance provides a way to give selective polymorphism
e.g. if a class only wants expose his interface to specific
clients, not necessarily because no true isA relationship exists,
but because selective clients may call the methods e.g.
I provide serviceA, ..B, and ..C. I don't want clientB to make
use of serviceA, but I nevertheless want to provide it to whom
I dictate (I've seen an article on this but can't remember where).
One could achieve the same by other means, but private inheritance
makes it easier. We have an example where we have two parallel
hierarchies (3 deep in this case, each level abstracting a
certain responsibility). The bases in the hierarchy make use of
template method pattern to dictate behavior in terms of
derived classes, and they in turn have enough information to
extend the template method (so to speak). Each of the
classes in the hierarchy make use of services provided by
the same class at different levels, and private inheritance
makes this possible. I have contemplated other ways to do
this, but decided that it is more natural to implement using
private inheritance. Of course, template method itself could
have been implemented using a <bridge>, if you know what I
mean? In the above mentioned case though, things played
out nicely using private inheritance and intent was very clear
(IMHO).