lundi 8 mars 2021

Iterator query C++

So I am working on a simple example which uses iterators. Here is a list of pair of ints and contains 2 elements initially. {1,1} -> {2,2} now I run the code below, so initially the it points to {2,2} so my understanding was that the iterator pointing to {2,2} is now copied in it and it will remain same but when I do values.pop_back() in the next line it automatically points to {1,1} now . How is this possible

can any one help me understand this behaviour ?

list<pair<int, int>>::reverse_iterator it = values.rbegin();
      values.pop_back();
      auto pos = locator.find( it->first);
      if( pos != locator.end())
      {
          locator.erase( pos);

      }

Aucun commentaire:

Enregistrer un commentaire