| | | | | |

ConstIterators

  • Same behavior as Iterator, except container may not be mutated
  • May be used when container is "const"
  • template < typename T >
      bool IsIn (const List<T>& list, T searchVal)
      {
        // List<T>::Iterator i;   // ERROR: const environment
        List<T>::ConstIterator i; // OK: using ConstIterator
        for (i = list.Begin(); i != list.End(); ++i) // calls "const" versions of Begin, End
        if (searchVal == *i)
          return true;
        return false;
      }
    
  • Note distinction between ConstIterator and const Iterator

| | Top of Page | 7. Iterators - 6 of 13