基类访问规范与成员访问规范有何不同?
答案 0 :(得分:2)
基类访问规范决定您的类中的基类'成员访问规范。如果您不希望它们在您的班级公开出现,它们提供了隐藏基类成员的方法。但它们不会影响班级成员的可见性。
C++ FAQ很好地解释了这个问题。
class Base
{
protected:
int A;
public:
int B;
};
class Derived1 : public Base
{
// Derived1::A outside class is seen as protected
// Derived1::B outside class is seen as public
};
class Derived2 : protected Base
{
// Derived1::A outside class is seen as protected
// Derived1::B outside class is seen as protected
};
class Derived3 : private Base
{
// Derived1::A outside class is seen as private
// Derived1::B outside class is seen as private
};