#ifndef TEMPLATELIST_HH #define TEMPLATELIST_HH /* * Interface definition for a C++ list class that uses templates. */ /* * Classes defined in this file: */ template class List; /* * Classes mentioned, but not defined, in this file: */ class IntListIterator; /* * Each element of the list (List::Element) consists of a value * and a pointer to the next element. The head of the list is * represented by the List class itself, which is the only thing * visible from the outside. */ template class List { friend IntListIterator; public: List(); ~List(); void push(const DATA& newValue); // Add a value to list DATA pop(); // Take a value off list private: /* * Auxiliary subclass that holds the actual data */ class Element { friend List; // List class does all work friend IntListIterator; private: Element(const DATA& value_, Element* next_ = NULL); ~Element(); Element* next; // Next element in list DATA value; // Value stored }; /* * Private data */ Element* head; // First element in the list }; /* * The g++ compiler can't handle templates unless it is given the * entire implementation at compile time. However, the user of the * template list really has no business (and no interest in) knowing * the details of the implementation. So we put it in a separate file * and include it here. (The same trick can be used for inline * functions, which have some similarity to templates.) */ #include "templatelist.icc" #endif // TEMPLATELIST_HH