2.2.2 When to use it?

private inheritance is much more restrictive than protected inheritance. In our example, none of the members of A is exposed to descendents of B or the public.

Again, one reason to use private inheritance is that the superclass may be predefined as a provided class. But now we have an additional question: why use private inheritance instead of protected inheritance? In other words, why do we want to hide members from descendents that are exposed from the superclass?

Again, the main objective is to hide interfaces that subclasses do not need to know. Getting back to the example in listing 2, let us assume the class XOStream provides all the primitives for an output file that confirms to a particular syntax. There may be a method to output a quoted string with escaped characters, another one to output a quoted character with escape code when necessary, and etc. If the designer of the class decides that there is no need to expose the basic output operators of strings and characters, then those methods can be hidden using private inheritance.

As a result, descendent (classes) of XOStream can only use whatever XOStream provides as public or protected members, or add their own methods. This helps to ensure the output file generated by a subclass of XOStream conform to a standard without characters and strings printed without quotes or escape code when needed.