Should I pointer-cast from a private derived class to its base class?
- by skydoor
I found this from C++FAQ
Generally, No.
From a member function or friend of a
privately derived class, the
relationship to the base class is
known, and the upward conversion from
PrivatelyDer* to Base* (or
PrivatelyDer& to Base&) is safe; no
cast is needed or recommended.
However users of PrivatelyDer should
avoid this unsafe conversion, since it
is based on a private decision of
PrivatelyDer, and is subject to change
without notice.
How to understand the above words? I don't think the explanation is correct or accurate.
I have a code like this
class A{
};
class B: private A{
};
int main(){
B *b = new B();
A *a = new A();
a = b; //wrong
a = (A*)b; //right
}