Private inheritance causing problem in c++
There's nothing wrong with your logic, except that it's missing one point:
private
inheritance basically means that only the inheriting class (B
in this case) knows that it inherits from the base A
.
That in turn means that only B
can make use of all the privileges that come with this inheritance. One of these privileges is to be able to cast B*
to A*
. The function foo()
doesn't know about B
's inheritance, so it cannot perform that cast.