Can I do this?
class A { ... };
class B : private A
{
const A &foo() const
{
return *((const A *)this);
}
};
Can I take a subclass that inherits privately from a base class and cast it to a public version of its base class? Can I do this without it having virtual methods?
My guess is yes, but I wanted to make sure it's safe / portable.
Yes you can: §5.4/7 of the standard:
But try not to as it defeats the purpose of private inheritance.