I have this simple question: in C++ primer 5ed by Lippman chapter 10. "The iterator categories" it is said:
The Iterator Categories
Input iterators: can read elements in a sequence. An input iterator must provide
Equality and inequality operators (
==
,!=
) to compare two iteratorsPrefix and postfix increment (
++
) to advance the iteratorDereference operator (
*
) to read an element; dereference may appear only on the right-hand side of an assignmentThe arrow operator (
->
) as a synonym for(*it).member
—that is, dereference the iterator and fetch a member from the underlying object.
Did he mean with "Dereference operator (*
) to read an element; dereference may appear only on the right-hand side of an assignment" : on the "left side of an assignment".??
I am confused about it. Thank you.
The author meant that if you have an input iterator it
, then you can do:
foo = *it;
but it's possible you may not be able to do:
*it = foo;
I.e. you can read from an iterator (it's on the right side of an assignment), but there is no guarantee you can write to it (it's on the left).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With