Bill Kotsias Bill Kotsias - 1 year ago 81
C++ Question

map<int,int> default values

std::map<int,int> mapy;

Is it safe to assume that
will always be 1? I mean, will
always get the default value of 0 before '++', even if not explicitly declared, as in my code?


Answer Source

As soon as you access the map with the [] operator, if the key doesn't exist it gets added. The default initializer of the int type gets invoked - so it will get a value of 0.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download