>public inheritance represents "is-a" relationship, whereas this is not the
case with private inheritance. This means that a class B which is privately
derived from A is NOT an object of type A and hence cannot be converted to
one (at least not by the compiler).
The "is-a" relationship does not exist for public users of the derived type,
but it does exist within the derived type and is available to friends of the
derived type who are then freely able to convert between the derived type and
its private base.
A popular C++ author describes this as "controlled polymorphism."
struct Base
{
};
class Derived : private Base
{
friend void FriendOfDerived();
};
void FriendOfDerived()
{
Derived d;
Base *bptr = &d; //Okay! Conversion available here!
}
int main()
{
Derived d;
Base *bptr = &d; //Error! Conversion not available here!
return 0;
}
Is this "controlled polymorphism" actually used in real-word designs?
I would be curious to know.