Call function from a pointer

Started by
4 comments, last by ConorJH 11 years, 9 months ago
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
Advertisement
What have you tried?
This might help you http://cplusplus.com/reference/stl/map/

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

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?
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 ;-)
@rnlf
Thanks, this is what I needed, works now xxx

This topic is closed to new replies.

Advertisement