Jump to content
  • Advertisement
Sign in to follow this  
ConorJH

Call function from a pointer

This topic is 2343 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

How do I create a map of ints and pointers to void functions, and then by giving the map an int, call a function?

Thanks

Share this post


Link to post
Share on other sites
Advertisement
http://www.newty.de/fpt/fpt.html#call

this but it seems to be talking about member functions. Im not even sure you can store function pointers in a map?

Share this post


Link to post
Share on other sites
You can. Pointers are first class data types in C++ and you can store any data typ in a map. Just all functions need to have the same signature. Syntax is:

Assuming you want to store pointers to functions returning int and taking no arguments:


// declare and insert
std::map<int, int(*)()> functions;
functions[10] = &my_func;
// call
functions[10]();


Nothing magic here ;-) Edited by rnlf

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!