Possible Duplicate:
Calling base class definition of virtual member function with function pointer
Given the following hierarchy:
struct Base
{
virtual void f() = 0;
};
void Base::f()
{
cout << "Base::f\n";
}
struct Derived : Base
{
void f()
{
cout << "Derived::f\n";
}
};
We can force a call to Base::f
like so:
Derived d;
d.Base::f();
or:
Base * b = &d;
b->Base::f();
No surprises there. But is it possible to obtain a member function pointer through which Base::f
can be called?
void (Base::*bf)() = &Base::f;
for_each( b, b+1, mem_fn( bf ) ); // calls Derived::f
(For the record, I don't actually have a need to do this. I'm just curious.)