I have a map
std::map<std::string, my_class*> name2ptr; I try to delete the contents of the map by first traversing through the map to delete the the my_class pointers and later clear the map. Now, I have a problem when there is only one pair in the map. The map has only one entry now
<"ajay", 0xabcd> It crashes at delete((*itr).second). The for loop is as below.
name_map_type::iterator itr; for( itr= name2ptr.begin();itr!=name2ptr.end();itr++){ if((*itr).second){ delete ((*itr).second); } } name2ptr.clear(); How can I solve this?