lundi 21 mai 2018

How to use iterator as parameters method?

I have this situation:

 void methodB(list<int>::iterator myIt){
    myIt++;
}
void methodA(){
    list<int> * myList=new list<int>();
    list<int>::iterator it=myList->begin();
    //many insertion in myList ...
    methodB(it);
    //...
}

I want that, when methodB ends, the iterator is one position forward but I can't do this... if I'm in methodA() and many times call methodB(it), every time the iterator is copied and when the control return to methodA() the it variable is always in myList->begin(). How can I solve this problem? Thanks

Aucun commentaire:

Enregistrer un commentaire