C++构造函数是protect的,子类的普通函数无法访问
我叫侯万楼 2019-07-23 03:58:31 // C++构造函数是protect的,子类的普通函数无法访问,但是子类的构造函数可以访问
class Base
{
protected: // protected
Base()
{
}
Base(const Base& base)
{
}
const Base& operator = (const Base&)
{
}
static void SFun()
{
}
void Fun()
{
}
};
class Son : public Base
{
public:
void Fun()
{
Base *p = new Base(); // error C2248: 'Base::Base': cannot access protected member declared in class 'Base'
Fun(); // OK
SFun(); // OK
}
Son()
{
}
Son(const Son & son)
{
}
};