A NullIterator is a concrete iterator that does nothing. As discussed in Section , every container has a NewIterator member function that returns a reference to an iterator instance. If a particular concrete container class does not provide an associated iterator class, its NewIterator member function returns a reference to a NullIterator. Program gives the declaration of the NullIterator class.
Program: NullIterator Class Definition
Because it is a concrete class, NullIterator provides implementations for all the pure virtual member functions of the Iterator class. As shown in Program , the implementation is trivial: The IsDone member function always returns true; the operator* member function always returns a reference to the NullObject instance; and the remaining functions do nothing at all.
Program: NullIterator Class Member Function Definitions
The default behavior of the NewIterator function of the Container class is to return a reference to a a new NullIterator instance as shown in Program .
Program: Container Class NewIterator Member Function Definition