Some time ago I have encountered a problem. When I was writing implementation of an interface class, I forgot to specify inheritance access-specifier, so the private-inheritance is assumed by default. It is illustrated in the following example:
And I used a factory to create an instance of the class B:
As you must know, private inheritance limits access to a base class for B class clients. But technically it is still accessible, see 11.2 paragraph 3 of the C++ standard:
Because of the rules on pointer conversions (4.10) and explicit casts (5.4), a conversion from a pointer to a derived class to a pointer to an inaccessible base class might be ill-formed if an implicit conversion is used, but well-formed if an explicit cast is used.
his is no a serious error, but this remind us that it is good when compiler finds out our typos, malformed and dangerous expressions. And it is good to set a maximum warning level when compiling code or use several compilers. As proverb says, two heads is better then one.
This is my first post in English, so feel free to send corrections. And of course, comments are welcome!