Archived

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

Greg K

Function Pointers

Recommended Posts

Greg K    122
I was wondering if it was possible to get the pointer to a function. I want to have a pointer void *pMyPointer = NULL; and a function void MyFunc( void ) { cout << "Hello" << endl; } and then assign the function to the pointer... pMyPointer = &MyFunc; so I can go pMyPointer(); Unfortunatly this does not work. Is there any way that something like this can be done? Thanks.

Share this post


Link to post
Share on other sites
EvilCrap    134
rtype (*NAME) (args);

how to cast:
  
int MyFunction(int,int);
int (*pMyFunction )(int,int) = MyFunction;
long pf = (long) MyFunction;
int x = ((int(*)(int,int))pf)(0,0);
pMyFunction(0,0);

Share this post


Link to post
Share on other sites