Howto retrieve a member function's address?

Started by
1 comment, last by Saib 21 years, 10 months ago
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.
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 ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Ah, I planned to look at the boost library some time soon anyway.

Thanks for the hint

This topic is closed to new replies.

Advertisement