在C++中,“conversion to inaccessible base class is not allowed”这个错误通常与类的继承权限和类型转换有关。下面我将逐一解释你提到的几个方面: 1. 解释“inaccessible base class”的含义 在C++中,如果一个基类(base class)对于派生类(derived class)或者外部代码来说是不可访问的,那么这个基类就被称为“inac...
b)static_cast<target-type>(expression), with extensions: pointer or reference to aderived classis additionally allowed to be cast to pointer or reference to unambiguous base class (and vice versa) even if the base class isinaccessible(that is, this cast ignores the private inheritance specifier)...
No validstandard conversionfrom “pointer toDerived” to “pointer toBase” exists. Ifexpressionis actually not a base class subobject of an object of typeDerived, the behavior is undefined. structB{};structD:B{B b;};D d;B&br1=d;B&br2=d.b;static_cast<D&>(br1);// OK, lvalue deno...
There is one thing you can do with a C-style cast that you can’t do with C++ casts: C-style casts can convert a derived object to a base class that is inaccessible (e.g. because it was privately inherited). static_castshould be used to cast most values ...
2)Iftarget-typeis “pointer to (possibly cv-qualified)Base” and the type ofexpressionis “pointer to (possibly cv-qualified)Derived” such thatBaseis a base class ofDerived, the result is a null pointer value ifexpressionis a null pointer value, or ...