<Al************@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
To iterate over the elements of any container type, we write
for (iter = container.begin(); iter != container.end(); ++iter)
do_soemthing_wtih_element (*iter);
why we write "++iter" instead of "iter++"?
The FAQ covers the efficiency aspect; but to me the reason is simpler than
that: because we want to point to the next element, nothing else...
Prefix increment, just increments; and in the case of iterators,
incrementing is pointing to the next element.
On the other hand; postfix increment stores the old state of the object,
increments the object, and returns the stored old state.
Since the for loop above only deals only with incrementing, the author of
the code uses prefix increment.
Ali