title: C++ Templates - LinkedList
body: <p>EDIT -- Answered below, missed the angled braces. Thanks all.</p>
  
  <p>I have been attempting to write a rudimentary singly linked list, which I can use in other programs. I wish it to be able to work with built-in and user defined types, meaning it must be templated.</p>
  
  <p>Due to this my node must also be templated, as I do not know the information it is going to store. I have written a node class as follows -</p>
  
  <pre><code>template &lt;class T&gt; class Node
  {
      T data; //the object information
      Node* next; //pointer to the next node element
  
  public:
      //Methods omitted for brevity
  };
  </code></pre>
  
  <p>My linked list class is implemented in a seperate class, and needs to instantiate a node when adding new nodes to the end of the list. I have implemented this as follows -</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "Node.h"
  using namespace std;
  
  template &lt;class T&gt; class CustomLinkedList
  {
      Node&lt;T&gt; *head, *tail;
  
  public:
  
      CustomLinkedList()
      {
          head = NULL;
          tail = NULL;
      }
  
      ~CustomLinkedList()
      {
  
      }
  
      //Method adds info to the end of the list
      void add(T info)
      {
          if(head == NULL) //if our list is currently empty
          {
              head = new Node&lt;T&gt;; //Create new node of type T
              head-&gt;setData(info);
              tail = head;
          }
          else //if not empty add to the end and move the tail
          {
              Node* temp = new Node&lt;T&gt;;
              temp-&gt;setData(info);
              temp-&gt;setNextNull();
              tail-&gt;setNext(temp);
              tail = tail-&gt;getNext();
          }
      }
  
      //print method omitted
  };
  </code></pre>
  
  <p>I have set up a driver/test class as follows -</p>
  
  <pre><code>#include "CustomLinkedList.h"
  using namespace std;
  
  int main()
  {
      CustomLinkedList&lt;int&gt; firstList;
  
      firstList.add(32);
      firstList.printlist();
      //Pause the program until input is received
      int i;
      cin &gt;&gt; i;
  
      return 0;
  }
  </code></pre>
  
  <p>I get an error upon compilation however - <strong>error C2955: 'Node' : use of class template requires template argument list</strong> - which points me to the following line of code in my add method - </p>
  
  <pre><code>Node* temp = new Node&lt;T&gt;;
  </code></pre>
  
  <p>I do not understand why this has no information about the type, since it was passed to linked list when created in my driver class. <strong>What should I be doing to pass the type information to Node?</strong></p>
  
  <p>Should I create a private node struct instead of a seperate class, and combine the methods of both classes in one file? I'm not certain this would overcome the problem, but I think it might. I would rather have seperate classes if possible though.</p>
  
  <p>Thanks, Andrew.</p>