This Code is giving error Heap-Use-After-Free
for (auto it = mp.begin();it != mp.end();it++)
{
if(it->second+ttl<=currentTime)
{
mp.erase(it);
}
}
But this code
for (auto it = mp.begin();it != mp.end();)
{
if(it->second+ttl<=currentTime)
{
mp.erase(it++);
}
else
{
++it;
}
}
Does Not give ans error. Can you please explain why? Both look basically the same to me. Please Help
Aucun commentaire:
Enregistrer un commentaire