get function member address

后端 未结 2 1899
[愿得一人]
[愿得一人] 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条回答
  •  旧时难觅i
    2021-01-22 20:36

    I'm not sure what you mean by "exact address". There's certainly no way of putting any address in an unsigned int (which is smaller than a pointer on my machine). For that matter, there's no way of putting a pointer to a function in a void*. Again, I've used machines where pointers to a function were larger than void*. And finally, there's no way of putting a pointer to (non-static) member function into a pointer to function; pointer to member functions are almost always larger. Finally, given:

    void (MyClass::*pmf)();
    MyClass* p;
    (p->*pmf)();
    

    mais call different functions, depending on the contents of p.

    So it's not at all clear what you're asking for.

提交回复
热议问题