Home > Back-end >  About unordered_map erase whether return the next position
About unordered_map erase whether return the next position

Time:09-25

In a class I use hash table to store the data, call the class's destructor wish to delete all elements,
To look up the information to the display on the net, use the erase function remove elements, when the parameter is an iterator returned by the iterator points to be removed after the element, but actually execute the following code, if not add in the erase the increase, it will be an error, this and I understand it,
 ClassA: : ~ ClassA 
{
Unordered_map & lt; Int, ClassB * & gt; : : iterator it=Amap. The begin ();
While (it!=Amap. End ())
{
The delete Amap - & gt; Second;
Amap. Erase (it++);
}
}

Trying to view source did not understand, can you tell me whether someone can explain the erase in delete store Pointers to elements of map/vector specific usage? Why do I try and online experience is not consistent?
Thank you very much!

CodePudding user response:

(
Supplement:
If, in accordance with the above code, that is, coupled with the increase in the erase, so can delete all in sequence,
But don't need to add in some experience such as http://c.biancheng.net/view/532.html can cycle on the,
)
  • Related