标签: c++
当我以保护模式继承类时,Derived* to Base*为何失败
Derived* to Base*
class Base { }; class Derived : protected Base { }; int main() { Base* b = new Derived(); // compile error }
答案 0 :(得分:0)
对基类的访问与对任何成员的访问相同。从外面,根本禁止进入。只有特权代码(可以访问其他受保护甚至私有部分的代码)才能以这种方式访问基类。