mardi 30 juin 2020

How do I remove element pointed to by iterator in a C++ list?

How do I remove element pointed to by iterator in a C++ list? why does not this work?

int main()
{
    list<int> l;
    l.push_back(5);
    l.push_back(6);

    
    for(auto &it: l)
    {
        l.erase(*it);
    }

    return 0;
}

Aucun commentaire:

Enregistrer un commentaire