• Advertisement

Archived

This topic is now archived and is closed to further replies.

Howto retrieve a member function's address?

This topic is 5744 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m writing a function pointer that can deal with any number of arguments as well as any calling convention (which includes __thiscall), while it is important that every such pointer is of the same type, i.e. that the class is not templatized. Casting, for whatever reason, does not work (not even reinterpret_cast), so I thought I''ll try to cheat with ASM, like so:
  
template <typename _ret, classname _class, typename _arg0>
void FuncPtr::PointToFunc (_ret (_class::* funcAddr)(_arg0) /*...*/)
{
    void* addr; // somehow need to cheat funcAddr to void*


    _asm
    {
        mov     addr, funcAddr // causes C2415, improper operand type
    }



    /*...*/
}
  
I''m aware that I would have to clone this function for every number of arguments a member function might have, but I could live with that. Does anyone know how to fix the above code? Another way of getting to know a member function''s address (it is in memory only once (hence the "this" pointer) so it must be possible) would of course be as much appreciated. Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
You don''t have to reinvent the wheel, use boost::function, it does what you want and can easily be combined with boost::bind for endless hours of coding fun.

(cf Boost link in .sig)

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]

Share this post


Link to post
Share on other sites
Ah, I planned to look at the boost library some time soon anyway.

Thanks for the hint

Share this post


Link to post
Share on other sites

  • Advertisement