previous | start | next

## Templates

- A template version of the `List` class presented in chapter 16 follows.

  >     template<typename T>
  >     class List
  >     {
  >     public:
  >        List();
  >        void push_back(T s);
  >        void insert(Iterator<T> pos, T s);
  >        void erase(Iterator<T> pos);
  >        Iterator<T> begin();
  >        Iterator<T> end();
  >     private:
  >        Node<T>* first;
  >        Node<T>* last;
  >     }

- Both the `Node` and `Iterator` classes need to be made templates as well.
- Each member function must also be made into a template.

  >     template<typename T>
  >     Iterator<T> List<T>::begin()
  >     {
  >        Iterator<T> iter;
  >        iter.position = first;
  >        iter.position = last;
  >        return iter;
  >     }

previous | start | next