Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C++

Get a Pointer to a Memberfunction

1.00/5 (1 vote)
25 Feb 2011CPOL 19.9K  
This shows you how to cast a Pointer to a Memberfunction to any Pointer Type you whish.
In my actual project, I needed a way to get a void* to a Memberfunction but the compiler would just throw cast errors at me. So I just used the way in which the compiler implemented these calls.

void* p;
__asm MOV eax,offset MyClass::MyFunction
__asm MOV p,eax


or as Macro:
#define MEMBERPTR(f,v) __asm MOV eax,offset f \
                         __asm MOV v,eax


This will give you the correct address of virtual and normal member functions.

Tested on MSVC++ 2008.
Might be different on other Compilers!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)