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
Call function from a pointer
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?
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:
Nothing magic here ;-)
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 ;-)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement