简体   繁体   English

为什么在保护模式下继承向上转换不起作用

[英]Why in protected mode inheritance upcasting is not working

When i am inheriting class in protected mode why Derived* to Base* is failing当我在保护模式下继承类时,为什么Derived* to Base*失败

class Base { };

class Derived : protected Base { };

int main()
{
   Base* b = new Derived(); // compile error
}

Access to the baseclasses is the same as access to any member.对基类的访问与对任何成员的访问相同。 From the outside, access is simply forbidden.从外面,访问是完全禁止的。 Only privileged code (code that can access other protected or even private parts) can access the baseclass in that way.只有特权代码(可以访问其他受保护甚至私有部分的代码)才能以这种方式访问​​基类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM