Why is that I cannot get the value of a key, in a const ref unordered_map that I have passed into the function, but I can for a local unordered_map ?
GameObject(const std::unordered_map<int,std::unordered_map<int,int>>& objectParameters){
if (objectParameters.find(CAPABILITY_TYPE_SPECIE)!=objectParameters.end()) {
//Following line gives an error:
auto map2 = objectParameters[CAPABILITY_TYPE_SPECIE];
//Following line works just fine
std::unordered_map<int,std::unordered_map<int,int>> objectParameters2;
auto map = objectParameters2[CAPABILITY_TYPE_SPECIE];
}
Why can't I get the value from objectParameters ? The error that the compiler complains is:
No viable overloaded operator[] for type 'const std::unordered_map >'
EDIT: Removing "const" from the type seems to make the error go away. Why is that ?
auto map2 = objectParameters.at(CAPABILITY_TYPE_SPECIE);
. Please look at Killzone Kid's answer! – Andreas H.