class A
{
public:
void virtual magic() = 0;
void bar()
{
magic(); // this should be legal
}
};
class B: public A
{
public:
void magic()
{
cout<<"implement magic here"<<endl;
}
};
class C: public B
{
void foo()
{
magic(); // this should not be allowed, i.e. create compile-time error
}
};
Run Code Online (Sandbox Code Playgroud)
因此,该纯虚基类A的B应访问magic(),但不排除任何派生类C的B.这可以使用访问说明符和/或朋友声明或以任何其他方式实现吗?