Possible Duplicate:
Why does a class used as a value in a STL map need a default constructor in …?
When I’m using a map, do values definitely get initialized to defaults or should I not rely on this?
For example, say I have the following code:
map<string, int> myMap;
cout << myMap["Hey"];
This will output “0” with my compiler. Is this guaranteed behavior? Is it possible that this wouldn’t always initialize to 0?
Quoth the standard:
So, not only is it guaranteed, but evaluating
myMap["Hey"]also causes the value 0 to be inserted into the map, if there was no entry for it before.