title: Error: Expected template-name before '<' token
body: <p>I'm trying to compile a program that implements chain and chainNodes and get errors at the following line (line 22):</p>
  
  <pre><code>class chain : public linearList&lt;T&gt;
  </code></pre>
  
  <p>The errors are: </p>
  
  <pre><code>Error: expected template-name before '&lt;' token
  Error: expected '{' before '&lt;' token
  Error: expected unqualified id before '&lt;' token
  </code></pre>
  
  <p>Any ideas why this is coming up? My code is below:</p>
  
  <pre><code>// linked implementation of a linear list
  // derives from abstract class linearList just to make sure
  // all methods of the ADT are implemented
  
  #ifndef chain_
  #define chain_
  
  #include&lt;iostream&gt;
  #include&lt;sstream&gt;
  #include&lt;string&gt;
  #include "linearList.h"
  #include "chainNode.h"
  #include "myExceptions.h"
  
  using namespace std;
  
  class linkedDigraph;
  template&lt;class T&gt; class linkedWDigraph;
  
  template&lt;class T&gt;
  class chain : public linearList&lt;T&gt;
  {
     friend linkedDigraph;
     friend linkedWDigraph&lt;int&gt;;
     friend linkedWDigraph&lt;float&gt;;
     friend linkedWDigraph&lt;double&gt;;
     public:
        // constructor, copy constructor and destructor
        chain(int initialCapacity = 10);
        chain(const chain&lt;T&gt;&amp;);
        ~chain();
  
        // ADT methods
        bool empty() const {return listSize == 0;}
        int size() const {return listSize;}
        T&amp; get(int theIndex) const;
        int indexOf(const T&amp; theElement) const;
        void erase(int theIndex);
        void insert(int theIndex, const T&amp; theElement);
        void output(ostream&amp; out) const;
  
     protected:
        void checkIndex(int theIndex) const;
              // throw illegalIndex if theIndex invalid
        chainNode&lt;T&gt;* firstNode;  // pointer to first node in chain
        int listSize;             // number of elements in list
  };
  
  template&lt;class T&gt;
  chain&lt;T&gt;::chain(int initialCapacity)
  {// Constructor.
     if (initialCapacity &lt; 1)
     {ostringstream s;
      s &lt;&lt; "Initial capacity = " &lt;&lt; initialCapacity &lt;&lt; " Must be &gt; 0";
      throw illegalParameterValue(s.str());
     }
     firstNode = NULL;
     listSize = 0;
  }
  
  template&lt;class T&gt;
  chain&lt;T&gt;::chain(const chain&lt;T&gt;&amp; theList)
  {// Copy constructor.
     listSize = theList.listSize;
  
     if (listSize == 0)
     {// theList is empty
        firstNode = NULL;
        return;
     }
  
     // non-empty list
     chainNode&lt;T&gt;* sourceNode = theList.firstNode;
                      // node in theList to copy from
     firstNode = new chainNode&lt;T&gt;(sourceNode-&gt;element);
                      // copy first element of theList
     sourceNode = sourceNode-&gt;next;
     chainNode&lt;T&gt;* targetNode = firstNode;
                      // current last node in *this
     while (sourceNode != NULL)
     {// copy remaining elements
        targetNode-&gt;next = new chainNode&lt;T&gt;(sourceNode-&gt;element);
        targetNode = targetNode-&gt;next;
        sourceNode = sourceNode-&gt;next;
     }
     targetNode-&gt;next = NULL; // end the chain
  }
  
  template&lt;class T&gt;
  chain&lt;T&gt;::~chain()
  {// Chain destructor. Delete all nodes in chain.
     while (firstNode != NULL)
     {// delete firstNode
        chainNode&lt;T&gt;* nextNode = firstNode-&gt;next;
        delete firstNode;
        firstNode = nextNode;
     }
  }
  
  template&lt;class T&gt;
  void chain&lt;T&gt;::checkIndex(int theIndex) const
  {// Verify that theIndex is between 0 and listSize - 1.
     if (theIndex &lt; 0 || theIndex &gt;= listSize)
     {ostringstream s;
      s &lt;&lt; "index = " &lt;&lt; theIndex &lt;&lt; " size = " &lt;&lt; listSize;
      throw illegalIndex(s.str());
     }
  
  }
  
  template&lt;class T&gt;
  T&amp; chain&lt;T&gt;::get(int theIndex) const
  {// Return element whose index is theIndex.
   // Throw illegalIndex exception if no such element.
     checkIndex(theIndex);
  
     // move to desired node
     chainNode&lt;T&gt;* currentNode = firstNode;
     for (int i = 0; i &lt; theIndex; i++)
        currentNode = currentNode-&gt;next;
  
     return currentNode-&gt;element;
  }
  
  template&lt;class T&gt;
  int chain&lt;T&gt;::indexOf(const T&amp; theElement) const
  {// Return index of first occurrence of theElement.
   // Return -1 if theElement not in list.
  
     // search the chain for theElement
     chainNode&lt;T&gt;* currentNode = firstNode;
     int index = 0;  // index of currentNode
     while (currentNode != NULL &amp;&amp; 
            currentNode-&gt;element != theElement)
     {
        // move to next node
        currentNode = currentNode-&gt;next;
        index++;
     }
  
     // make sure we found matching element
     if (currentNode == NULL)
        return -1;
     else
        return index;
  }
  
  template&lt;class T&gt;
  void chain&lt;T&gt;::erase(int theIndex)
  {// Delete the element whose index is theIndex.
   // Throw illegalIndex exception if no such element.
     checkIndex(theIndex);
  
     // valid index, locate node with element to delete
     chainNode&lt;T&gt;* deleteNode;
     if (theIndex == 0)
     {// remove first node from chain
        deleteNode = firstNode;
        firstNode = firstNode-&gt;next;
     }
     else 
     {  // use p to get to predecessor of desired node
        chainNode&lt;T&gt;* p = firstNode;
        for (int i = 0; i &lt; theIndex - 1; i++)
           p = p-&gt;next;
  
        deleteNode = p-&gt;next;
        p-&gt;next = p-&gt;next-&gt;next; // remove deleteNode from chain
     }
     listSize--;
     delete deleteNode;
  }
  
  template&lt;class T&gt;
  void chain&lt;T&gt;::insert(int theIndex, const T&amp; theElement)
  {// Insert theElement so that its index is theIndex.
     if (theIndex &lt; 0 || theIndex &gt; listSize)
     {// invalid index
        ostringstream s;
        s &lt;&lt; "index = " &lt;&lt; theIndex &lt;&lt; " size = " &lt;&lt; listSize;
        throw illegalIndex(s.str());
     }
  
     if (theIndex == 0)
        // insert at front
        firstNode = new chainNode&lt;T&gt;(theElement, firstNode);
     else
     {  // find predecessor of new element
        chainNode&lt;T&gt;* p = firstNode;
        for (int i = 0; i &lt; theIndex - 1; i++)
           p = p-&gt;next;
  
        // insert after p
        p-&gt;next = new chainNode&lt;T&gt;(theElement, p-&gt;next);
     }
     listSize++;
  }
  
  template&lt;class T&gt;
  void chain&lt;T&gt;::output(ostream&amp; out) const
  {// Put the list into the stream out.
     for (chainNode&lt;T&gt;* currentNode = firstNode;
                        currentNode != NULL;
                        currentNode = currentNode-&gt;next)
        out &lt;&lt; currentNode-&gt;element &lt;&lt; "  ";
  }
  
  // overload &lt;&lt;
  template &lt;class T&gt;
  ostream&amp; operator&lt;&lt;(ostream&amp; out, const chain&lt;T&gt;&amp; x)
     {x.output(out); return out;}
  
  #endif
  </code></pre>
  
  <p>Below is linearList.h</p>
  
  <pre><code>#ifndef linear_ 
  #define linear_
  
  
  #include &lt;iostream&gt;
  
  
  using namespace std; 
  
  
  class linearList 
  {
     public:
        virtual ~linearList() {};
        virtual bool empty() const = 0;
        virtual int size() const = 0;
        virtual int* get(int theIndex) const = 0;
        virtual int indexOf(const int&amp; theElement)const = 0;
        virtual void erase(int theIndex) = 0;
        virtual void insert(int theIndex,
                            const int&amp; theElement) = 0;
      virtual void traverse()=0;
       virtual void MaxMin()=0;
  
  //      virtual void output(ostream&amp; out) const = 0;
  };
  #endif
  </code></pre>