获取函数成员地址

获取函数成员地址

问题描述:

有没有办法获得函数成员的确切地址?
例如我有:

Is there any way to get the exact address of a function member? For example I have :

struct foo
{
    void print() { printf("bla bla bla"); }
};
//////////////////////////////////////////////////////////////
unsigned int address = foo::print;


您可以使用以下语法声明指针成员函数:

You can use the following syntax to declare the pointer to the member function:

typedef void (foo::*address)();
address func = &foo::print;

为了调用非静态成员函数,您将需要该类的现有实例:

In order to call non-static member function you will need an existing instance of that class:

(fooInstance.*func)();