Base on your question title, the answere depends. But for your case in your source code, the answere is yes.
There are two factor which will impact the answere:
If you using C style cast, it will yes, because cast will call re-interpert cast if no conversion availible. You can cast any type of pointer to the target type of pointer. But if there is MI, the result may be incorrect for most C++ language implementation.
If you do the cast (without C style cast) inside the memeber function, the answere will be yes, because the base class is accessable inside the member function. If the expression is in the location where the base class is inaccessable, you will got compile error.
There are more detail about standard converstion in the C++ standard
A prvalue of type “pointer to cv D”, where D is a class type, can be converted to a prvalue of type “pointer to cv B”, where B is a base class (Clause 10) of D.
If B is an inaccessible (Clause 11) or ambiguous (10.2) base class of D, a program that necessitates this conversion is ill-formed.
The result of the conversion is a pointer to the base class subobject of the derived class object. The null pointer value is converted to the null pointer value of the destination type.
Edit 2: make the answere more detail.
private
relationship:B b; A& ar = *(A*)&b;
will gladly compile even outside of theB
class (i.e. access specifiers are ignored by the C-style cast) – SellersT
. Inheritance fromT
is not your interface, is a requirement for your particular implementation, and if you change the provider, that inheritance can be dropped without affecting user code. – Sellers