基类访问规范与成员访问规范有何不同?
问问题
2090 次
1 回答
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
};
于 2013-02-26T05:42:31.470 回答