确定派生类是否覆盖基类中的方法

del*_*106 10 c++ virtual rtti

class B {
virtual int foo();
};

class D : public B {
virtual int foo() { cout<<"D\n"; }
};

int B::foo()
{
   /* how do i tell if this->foo() is overridden by a subclass, or if it will */
   /* simply recurse into B::foo()? */
   this->foo();
}

main()
{
D d;
d.B::foo();
}
Run Code Online (Sandbox Code Playgroud)

Edw*_*nge 8

答:你不能.

如果有任何可扩展的话,我会扩展.