C++中受保护的继承

Protected Inheritance in C++

本文关键字:继承 受保护 C++      更新时间:2023-10-16

简单代码:

class A
{
private: int a;
protected: int b;
public: int c;
};
class B : protected A
{
};
class C : protected B
{
};

我知道在B班,a将保持私有&b和c受到保护。

但我感到困惑的是,C类中的访问说明符是什么?

有了protected继承,继承的public成员就变成了protected

随着private的继承,publicprotected的成员变成了private