I was wondering how to properly delete a pointer which is the first key of a std::map. I can only figure this out for the second key. The first key is only readable.
Example:
std::map<char*,foo> myMap;
char* str = new char[3];
foo bar;
str[0]='h';
str[1]='i';
str[2]='\0';
myMap[str] = bar
/* some code */
for(auto element: myMap)
{
delete [] element.first;
}
This doesn't seem to free the pointer. Did std::map lose the pointer somewhere? I am working on big data, so I need string structures as light as possible. That's why I worked with char* and not std::string (with a comparator functor given to the map).
Aucun commentaire:
Enregistrer un commentaire