See std::map::insert and std::map for value_type
myMap.insert(std::map<std::string, myFunc>::value_type("test", &Test::TestFunc));
and for operator[]
myMap["test"] = &Test::TestFunc;
You cannot use a pointer to a member function without an object. You can use a pointer to a member function with an object of type Test
Test t; myFunc f = myMap["test"]; std::string s = (t.*f)("Hello, world!");
or pointer to type Test
Test *p = new Test(); myFunc f = myMap["test"]; std::string s = (p->*f)("Hello, world!");
See Also C ++ Frequently Asked Questions - Member Function Pointers
source share