I am trying to create a std::map that has an integer as the key and a function as the value. When I try to insert a value, either via = or insert(), I get the following error:
Error C2207 'std::pair<_Ty1,_Ty2>::second': a member of a class template cannot acquire a function type
Here is the sample code:
std::map<int, std::function<void()>> myMap;
myMap[0] = [] {std::cout << "zero\n"; };
myMap.insert(std::make_pair<int, std::function<void()> >(0, [] {std::cout << "zero\n";} ) )
Why can't I do this, and how do I fix it?
std::function<void>()-->std::function<void()>in the declaration ofmyMap.@it suggestsπάνταῥεῖ(only), because they're the only commenter here with unprintable characters in the name. On the other hand, when I do@H(cyrillic Н on a cyrillic keyboard), I don't get any suggestion, because you're not supposed to@the OP.std::make_pair(), always let it deduce the parameters.