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?