October 1999
Beginner
304 pages
7h 11m
English
The obvious question is, how do we implement this layer of abstraction? We need a collection of objects that support the same set of operators as the built-in pointer (++, *, ==, !=) but allow us to provide a unique implementation of those operators. We can do exactly this with the C++ class mechanism. We’ll design a set of iterator classes that are programmed using the same syntax as that of a pointer. For example, if first and last are list class iterators, we can write
// first and last are iterator class objects
while ( first != last )
{
cout << *first << ' ';
++first;
} the same as if first and last are actual pointers. The difference is that the dereference operator (*), the inequality operator (!=), and ...
Read now
Unlock full access