In general, the default constructor does not have a map element value.
This was required in C ++ 03, but this requirement was dropped in C ++ 11, which often instead of creating requirements in the container uses a finer-grained requirements scheme with requirements for using specific member functions.
map::operator[] is one of these member functions because it will create an element with the given key and default value if the element with the key does not exist.
This is also the reason why the const version of map::operator[] does not exist: it potentially modifies the map.
In C ++ 11 and later, you can use the at accessory to access an element with a given key on a const map without the granularity and complexity of find .
Since map::at does not attempt to create an element, it does not require the element type to be constructive by default.
So, one practical solution to your problem is to use map::at instead of map::operator[] .
source share