For instance, I have below code.
#include <iostream>
#include <map>
using namespace std;
typedef map <int, string> mapType;
mapType myMap = {{1, "One"}, {2, "Two"}, {3, "Three"}};
int main() {
for (auto itr = myMap.begin(); itr != myMap.end(); ++itr) {
cout << itr->first << " " << itr->second << '\n';
}
return 0;
}
It works absolutely fine in linux environment(GCC 4.8x) but in case of solaris(Oracle Solaris Studio, version 12.6) I'm getting below error.
Could not find a match for std::map<int,std::string>::map({initializer list}) needed in file level.
I have gone through the various blogs and tried to initialize map with different ways but didn't work. For example below code has resulted in same error.
mapType myMap {{1, "One"}, {2, "Two"}, {3, "Three"}};
mapType myMap = mapType {{1, "One"}, {2, "Two"}, {3, "Three"}};
I want this map to be global so that it can be accessed from different files. Any suggestions would be really helpful.