我想创建一个map具有 string关键和通用的方法,value在C++中,但我不知道这甚至有可能.我想做那样的事情:
void foo(int x, int y)
{
//do something
}
void bar(std::string x, int y, int z)
{
//do something
}
void main()
{
std::map<std::string, "Any Method"> map;
map["foo"] = &foo; //store the methods in the map
map["bar"] = &bar;
map["foo"](1, 2); //call them with parameters I get at runtime
map["bar"]("Hello", 1, 2);
}
Run Code Online (Sandbox Code Playgroud)
那可能吗?如果是的话,我怎么能意识到这一点?
c++ ×1