How to initialize the unordered_map in C++98. I am trying below:
1. const std::tr1::unordered_map<std::string, int> mymap = {{key1,1}};
2. const std::tr1::unordered_map<std::string, int> mymap = {std::make_pair(key1,1)};
Compiler throws error:
C++98 ‘mymap’ must be initialized by constructor, not by ‘{...}’
I learnt from Stackoverflow that the above method is initializer list which is supported from C++11 onwards. Can you tell me how to initialize mymap? Oneway I am thinking is to insert pairs one by one in to mymap.
in C++98 you can't initialize something like a map when you declare it. You can only insert each pair as a separate statement: