编译器警告(等级 3)C4243
从“type1”到“type2”存在“conversion type”转换,但它是不可访问的
派生类的指针会转换为基类的指针,但该派生类会继承具有专用访问权限或受保护访问权限的基类。
下面的示例生成 C4243:
// C4243.cpp
// compile with: /W3
// C4243 expected
struct B {
int f() {
return 0;
};
};
struct D : private B {};
struct E : public B {};
int main() {
// Delete the following 2 lines to resolve.
int (D::* d)() = (int(D::*)()) &B::f;
d;
int (E::* e)() = (int(E::*)()) &B::f; // OK
e;
}