Jump to content
  • Advertisement

Archived

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

Greg K

Function Pointers

This topic is 6064 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 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
Advertisement
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!