map RectMap; <- error typedef unsigned key_type; <- any type you want std::map<key_type, SRect> RectMap; <- OK SRect sr = {iX, iY, iW, iH}; <- should work RectMap[iID] = sr; OR RectMap[iID] = {iX, iY, iW, iH}; <- should work Only write something like RectMap[iID]->iX if you are storing pointers to type sRect in the map; which would be bad and stuped unless you have a really good reason for doing so. If you are storing pointers ( std::map<key_type, SRect*> ) in the map, then you will need to write a method to free the memory pointed to by all those elements before you allow the map to be destroyed. If you are storing the actual data instead ( std::map<key_type, SRect> ), then the clean up will be automatic when the map is destroyed. To recap: ... BAD ...
std::map<key_type, SRect*> RectMap; <- bad
RectMap[key] = new SRect(iX, iY, iW, iH); <- this is why it is bad
void cleanup_before_destruction() <- and this is why it is bad
{
std::map<key_type, SRect*>::iterator i;
for( i = RectMap.begin(); i != RectMap.end(); ++i )
delete *i;
}
... GOOD ...
std::map<key_type, SRect> RectMap; <- good
SRect sr(iX, iY, iW, iH);
RectMap[key] = sr;
INTP "Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra