Re: Question on iterator. Why is a pointer?
On 2009-01-22 18:09:45 -0500, Hongyu <hongyu_wu@yahoo.com> said:
Dear all:
I am reading "Thinking in C++" volume 2, p629, and have a question on
the below code:
......
static void run( ) {
vector<Task *>::iterator it = tasks.begin( );
while (it != tasks.end())
(*it++)->operation( );
}
.....
My question here is: why use (*it++)-> for the iterator it? which
indicate that it is a pointer. But from the defination, I only see
vector<Task *>::iterator it = tasks.begin( );, instead of vector<Task
*>::iterator *it; The vector <Task *> only indicate that the vector
contains <Task *> inside, doesn't mean it is a pointer, if from the
defination above, no pointer * is in front of it.
I believe the book is correct. But what's wrong with my understanding.
Any help for clarifying this will be appreciated.
Iterators provide many of the operators that pointers provide,
including operator++ and operator->. The idea is to make the syntax of
iterators look like the syntax of pointers so that you can use them
more or less interchangeably.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)