是什么区别public,private以及protected用C++继承?我在SO上发现的所有问题都涉及具体案例.
我完全不懂这个:
class Base
{
public:
Base()
{
cout<<"Base" << endl;
}
virtual void call()
{
cout<<"Base call" << endl;
}
};
class Derived: private Base
{
public:
Derived()
{
cout<<"Derived" << endl;
}
};
int main(void)
{
Base *bPtr = new Derived(); // This is not allowed
}
Run Code Online (Sandbox Code Playgroud)
是因为有人可能使用bPtr调用call(),这实际上是在派生对象上完成的?或者还有其他原因吗?