Skip to main content
gamedev.net
🔒 Locked

Function Pointers

Started by Greg K Jan 10, 2002 at 12:05 AM 1 replies 350+ views
Original Post
Greg K
Greg K
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.
scaught
scaught
Yup. You want:

  
void (*pMyPointer)(void) = NULL;

pMyPointer = MyFunc;


pMyPointer() will work fine.

-scott
EvilCrap
EvilCrap
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);

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.