While it is possible for inheritance to be non-public
, it is rarely justified and complicates the use of the derived class. For
instance, inherited member visibility is diminished and implicit and static_cast
casts from the derived class to the base class will not
work.
It is sometimes used to limit the base class functionality available in the derived class. When that is the desire, composition should be used
instead.
Noncompliant code example
class B : private A { // Noncompliant
// ...
}
Compliant solution
class B : public A {
// ...
}
or
class B {
private:
A a;
// ...
}