Hi guys,
I have a question regarding the passing of a map by reference. Let's consider the following piece of codes:
void doNotChangeParams(const map<int, int>& aMap){
if (aMap.find(0) != aMap.end()){
cout << "map[0] = " << aMap[0] << endl;
}
}
and I'm having a map myMap and make a call like this: doNotChangeParams(myMap)
Now, it can be seen that I'm not modifying the parameter aMap inside the function. Nevertheless my g++ compiler complains that the access aMap[0] discards the qualifier const.
I'm putting const since I want to both tell readers of this function that I'm not modifying the argument. Also, it helps throws compile errors when I accidentally modify the map.
Currently, I have to drop the const and I think it would make the above meaning unclear to the reader from the signature of the method. I know a comment would do, but I figure I would just ask in case you know of any "programmatic" ways.
Thanks, guys.