View Single Post
Old 04-10-2003, 11:06 AM   #5 (permalink)
Unicorn
Registered User
 
Unicorn's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 11
Unicorn is on a distinguished road
I hope I understand the problem correctly.

The anatomy of a pointer to a (virtual) member function in Base looks like this:
Code:
return_type (Base::*)(param_type);
If you want to store a pointer to a member function, and call it later on, you must invoke it on an object:
Code:
class Base
{
public:
    virtual void Foo () { cout << "Foo in Base" << endl; }
};

class Derived : public Base
{
public:
    virtual void Foo () { cout << "Foo in Derived" << endl; }
};

int main ()
{
    typedef void(Base::*FunctionPtr)();

    FunctionPtr foo_function = &Base::Foo;

    Base Obj1;
    Derived Obj2;

    (Obj1.*(foo_function))();
    (Obj2.*(foo_function))();

    return 0;
}
Unicorn is offline   Reply With Quote