map<constchar*, int, Comparator> map_Keys; //Comparator is defined elsewhere
I need to clear the map after the use of it. Does following is valid for that?
1 2 3 4 5 6 7 8 9
map<constchar*, int, Comparator>::iterator ite = map_Keys.begin();
while ( ite != map_Keys.end() )
{
delete [] ite->first;
ite->first = NULL;
map_Keys.erase(ite); //I'm not sure does this advances the ite for next element
}
If the keys are strings why not use std::string instead? If it's just some char data array why not use std::vector? That way you don't need use a custom comparator (unless you have special needs).
Right, I missed the fact that you wanted to delete the pointers and then clear the map. That is a valid approach--to loop once to delete and then call clear.