I’m a little bit scared about something like this:
std::map<DWORD, DWORD> tmap;
tmap[0]+=1;
tmap[0]+=1;
tmap[0]+=1;
Since DWORD’s are not automatically initialized, I’m always afraid of tmap[0] being a random number that is incremented. How does the map know hot to initialize a DWORD if the runtime does not know how to do it?
Is it guaranteed, that the result is always tmap[0] == 3?
The new object, when inserted into the map by
[]operator, is value-initialized. It is ensured by the map implementation, i.e. it is done “automatically” in that sense. For objects of typeDWORD(assuming it is a scalar type), value-initialization means zero-initialization.By definition given in 23.3.1.2,
operator []is a shorthand forThe
T()bit is the new object, which will turn intoDWORD()in your case.DWORD()is guaranteed to be zero.