0
class MyObject{
public:
void testFunctionMap(){
std::unordered_map<std::string, std::function<void()> > functionMap;
std::pair<std::string, std::function<void()> > myPair("print", std::bind(&MyObject::printSomeText, this));
functionMap.insert(myPair);
functionMap["print"]();
}
void printSomeText()
{
std::cout << "Printing some text";
}
};
MyObject o;
o.testFunctionMap();
這工作正常。是否有另一種方法使用MyObject :: printSomeText函數作爲該對的值?如何創建一個unordered_map爲字符串功能