N
Nick Keighley
Hi,
I have a map containing pointers. When I destroy the map I want to
delete
all the pointers.
typedef std::map<std::string, const T*> Table;
void destroy_map ()
{
for (Table::iterator i = table_.begin(); i != table_.end(); ++i)
{
delete (*i).second;
table_.erase (i);
}
}
this crashes. Does the erase() invalidate the iterator?
This was the code I found on the net (latout fixed a bit)
for (map::iterator itr = myMap.begin(); itr != myMap.end())
{
if(itr->value == something)
myMap.erase(itr++);
else
itr++;
}
which it is claimed is from Josuttis. I suppose the fact that it
didn't compile should of made me doubt this...
I have a map containing pointers. When I destroy the map I want to
delete
all the pointers.
typedef std::map<std::string, const T*> Table;
void destroy_map ()
{
for (Table::iterator i = table_.begin(); i != table_.end(); ++i)
{
delete (*i).second;
table_.erase (i);
}
}
this crashes. Does the erase() invalidate the iterator?
This was the code I found on the net (latout fixed a bit)
for (map::iterator itr = myMap.begin(); itr != myMap.end())
{
if(itr->value == something)
myMap.erase(itr++);
else
itr++;
}
which it is claimed is from Josuttis. I suppose the fact that it
didn't compile should of made me doubt this...