get function member address

后端 未结 2 1920
[愿得一人]
[愿得一人] 2021-01-22 19:58

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\"); }
};
//////////////         


        
2条回答
  •  迷失自我
    2021-01-22 20:15

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

提交回复
热议问题