0

Say, I have an iterator

vector<int> myVector;
vector<int>::iterator myIt;
for (myIt=myVector.begin(); myIt!=myVector.end(); ++myIt)
{

}

what if I use myIt++ instead of ++myIt.

I got this question, when I read How do I iterate over a Constant Vector? it says "Please read about prefix versus postfix increment operator. it++ should be ++it, and it++ is needed in rare cases (i.e. when erasing while iterating)." So, I am kind of confused

Thanks.

Community
  • 1
  • 1

1 Answers1

1

In the context you use it, the result will be the same. However, the post-incerement and pre-increment operator are different things which basically can be implemented independently.

Codor
  • 17,447
  • 9
  • 29
  • 56
  • Let me clarify it. I got this question, when I read http://stackoverflow.com/questions/4890497/how-do-i-iterate-over-a-constant-vector it says "Please read about prefix versus postfix increment operator. it++ should be ++it, and it++ is needed in rare cases (i.e. when erasing while iterating)." So, I am kind of confused – user3440433 Jan 13 '15 at 14:41