If the element does not exist in the map , operator [] adds it - which obviously cannot work in the const map, therefore C ++ does not determine the version of the const operator. This is a good example of compiler type checking, preventing a potential runtime error.
In your case, you need to use find , which will only return the element (iterator to the), if it exists, it will never change the value of map . If the element does not exist, it returns an iterator to the end() maps.
at does not exist and should not compile. Perhaps this is a "compiler extension" (= mistake new in C ++ 0x).
Konrad Rudolph Feb 27 2018-11-21T00: 00Z
source share