c++ function ptr in unorderer_map, compile time error -
i trying implements unorderer_map implements mapped_type, watching examples implements these cannot make work. here code:
#include<string> #include <unordered_map> namespace test { class example { public: example() { auto apair=std::make_pair("one",&example::processtring); map.insert(apair); } void processtring(std::string & astring) { } void processstringtwo(std::string & astring) { } typedef void(*fnptr)(std::string &); std::unordered_map<std::string,fnptr> map; }; } int main() { return 0; }
i compile time error:
error: no matching function call 'std::unordered_map, void (*)(std::basic_string&)>::insert(std::pair, void (test::example::*)(std::basic_string&)>&)'
thx!
a function pointer , member function pointer 2 different things. either need add free function map or need change map take member function pointer instead. if want take member function pointer can use this:
typedef void(example::*fnptr)(std::string &);
Comments
Post a Comment