Category : dictionary

I want to use std::function<void()> as a typename in initializing a map: void warning() {} void error() { exit(1); } std::map<std::string, std::function<void()>> msgtypes = { { "WARNING", warning }, { "ERROR", error } }; But it’s not working: error: could not convert ‘{{"WARNING", ((kc::kcmessage*)this)->kc::kcmessage::warning}, {"ERROR", ((kc::kcmessage*)this)->kc::kcmessage::error}}’ from ‘<brace-enclosed initializer list>’ to ‘std::map<std::__cxx11::basic_string<char>, std::function<void()> >’ (<brace-enclosed ..

Read more