为什么这不会编译?我错过了什么?
class Base
{
public:
Base() : data(0) { }
protected:
int data;
};
class Derived : public Base
{
public:
Derived() : Base() { }
Derived& operator=(const Base& _base)
{
data = _base.data; // protected member Base::data is not accessible through a "Base" pointer or object.
}
};
为什么会这样,因为数据成员具有受保护的可见性(以便派生类可以访问它)。