I can compile this code that I got from an MSDN page:
using namespace std typedef std::unordered_map<char, int> Mymap; Mymap c1; c1.insert(Mymap::value_type('a', 1)); c1.insert(Mymap::value_type('b', 2)); c1.insert(Mymap::value_type('c', 3)); But when I change it to be:
using namespace std typedef std::unordered_map<int, vector<int> > Mymap; Mymap c1; c1.insert(Mymap::value_type(1, vector<int> v (1,1))); c1.insert(Mymap::value_type(2, vector<int> v (1,2))); c1.insert(Mymap::value_type(3, vector<int> v (1,3))); I get the errors (the line numbers are obviously off for the snippet):
myfile.cpp:121:29: error: expected primary-expression before ‘(’ token myfile.cpp:121:45: error: expected primary-expression before ‘v’ myfile.cpp:122:32: error: expected primary-expression before ‘(’ token myfile.cpp:122:48: error: expected primary-expression before ‘v’ myfile.cpp:123:32: error: expected primary-expression before ‘(’ token myfile.cpp:123:48: error: expected primary-expression before ‘v’ The hash map should be "int => list of ints". With the list being initialized with one number.
What is the problem here? Do I need to use something other than value_type ?