How to insert a method to std::map for calling function by name (string)?
I'm working on a manager program. I want to make a event listening like
(but not same) manager handling system. Here is my work:
std::map<char*, void> functions; //There is a map for listing method
name-method
void a() { printf("a called!"); } //Method for testing
void b() { printf("b called!"); } //Method for testing
void addHandler(char* type, void target) //Add method to list for calling
them later
{
functions.insert(std::pair<char*, void>(type, target));
}
int main()
{
addHandler("test", a); //I'm adding method to my list
//I'll call "test" method in here
return 0;
}
Now there is to problems about the system. First one is; How can I add a
method to my list? and the other one; How can I call them later? Maybe
only getting map value but I don't think so (I can't do it)
No comments:
Post a Comment