Class inheritance is private by default ( class B : A {}; default is class B : private A {}; ).
So you cannot handle b through type A
EDIT: Like Rob said :), a way to fix this using public inheritance:
class B : public A {};
EDIT:
The connection between a public derived class and its base class is "there", which means that it is a specialization of a more general type, and as such it implements the behavior of this generic class and, possibly, more.
The relationship between a private derived class and its base class is "in terms of". This does not allow objects to be considered extensions of the base class. A good example of its use is boost::noncopyable , which prevents copying of objects of a class derived from a private class. http://www.boost.org/doc/libs/1_52_0/libs/utility/utility.htm#Class_noncopyable
In the hypothetical case that the requirements include private inheritance, and at some point a function is created that wants to refer to the object as its base, the public method that returns the casted to base class this pointer will be very similar to the traditional get() call A private data item that supports the original target.
public: A *getBase() { return static_cast<A *>(this); }
And then follow these steps:
f(b.getBase());
source share