Search code examples
c++virtualrtti

Determining if a derived class overrides a method from a base class


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();
}

Solution

  • Answer: you can't.

    I'd expand if there was anything to expand upon.