Is this a good way to delete a map of longs and objects made with new
// iterate over the map
for (std::map<unsigned long, Object*>::iterator it = objects.begin(), it_end = objects.end(); it != it_end; ++it)
{
Object* temp = it->second;
if(temp)
delete temp;
}
// clear the map
objects.clear();
Yes, although the better solution would be to use smart pointers instead of
Object*, but that is a different subject.You could shorten the content of the for to
delete nullis defined and is a noop.