I'm trying to understand the private inheritance concept.
So far everywhere I see they write that private inheritance makes its members inaccessible from the derived class.
Doesn't this make it sort of useless? If I can't access the class inherited, what is the purpose of deriving in the first place?
Now I know private classes are actually used and helpful. I'm just having trouble in understanding how.
Your question reads as if
privatemembers would be useless altogether. I mean you could as well ask, what is a private member good for if it cannot be accessed from outside. However, a class (usually) has more than what a subclass can use.Consider this simple example:
A class inheriting from
barwont even notice thatbarinherits fromfoo. Nevertheless, it does make sense forbarto inherit fromfoo, because it uses its functionality.Note that private inheritance is actually closer to composition rather than public inheritance, and the above could also be
Outside of the class: You dont, thats what the
privateis for. It's not different for private members or private methods in general, they are there for a reason, you just cannot access them from outside.