title: Constructor linker error using template
body: <p>I just started using template. </p>
  
  <p>I want to create a linked list class which stores the address of Type (could be an object). Here is the layout of my project:</p>
  
  <pre><code>linkedlist.h
  node.h
  node.cpp
  linkedlist.cpp
  main.cpp
  </code></pre>
  
  <p><strong>Node.h</strong></p>
  
  <pre><code>template &lt;class Type&gt; struct Node
  {
  public:
      Node&lt;Type&gt;();
      Node&lt;Type&gt;(Type* x = 0, Node* pNext = 0);
      Type* data;
      Node* next;
  };
  </code></pre>
  
  <p><strong>Node.cpp</strong></p>
  
  <pre><code>#include "node.h"
  
  template&lt;class Type&gt; Node&lt;Type&gt;::Node()
  {
      next = 0;
      data = 0;
  }
  template&lt;class Type&gt; Node&lt;Type&gt;::Node(Type* item, Node* ptrNext)
  {
      next = ptrNext;
      data = item;
  }
  </code></pre>
  
  <p><strong>linkedlist.h</strong></p>
  
  <pre><code>#include "node.h"
  
  template &lt;class Type&gt; class LinkedList
  {
  private:
      Node&lt;Type&gt;* root;
  
  public:
      LinkedList&lt;Type&gt;();
      ~LinkedList&lt;Type&gt;();
      void insert(Type*);
      void remove(Type*);
  };
  </code></pre>
  
  <p><strong>linkedlist.cpp</strong></p>
  
  <pre><code>#include "linkedlist.h"
  
  template &lt;class Type&gt; LinkedList&lt;Type&gt;::LinkedList()
  {
      root = 0;
  }
  
  template &lt;class Type&gt; LinkedList&lt;Type&gt;::~LinkedList()
  {
      Node* p;
      while(p = root)
      {
          root = p-&gt;next;
          delete p;
      }
  }
  // many more....
  </code></pre>
  
  <p>In main.cpp, I have the following:</p>
  
  <pre><code>int main()
  {
      int *ptrA, *ptrB;
      int a = 100, b = 10;
  
      ptrA = &amp;a;
      ptrB = &amp;b;
  
      LinkedList&lt;int&gt;myList;
      myList.insert(ptrA);
      return 0;
  }
  </code></pre>
  
  <p>and compiler threw linker errors:</p>
  
  <pre><code>1&gt;main.obj : error LNK2019: unresolved external symbol "public: __thiscall LinkedList&lt;int&gt;::~LinkedList&lt;int&gt;(void)" (??1?$LinkedList@H@@QAE@XZ) referenced in function _main
  1&gt;main.obj : error LNK2019: unresolved external symbol "public: void __thiscall LinkedList&lt;int&gt;::insert(int *)" (?insert@?$LinkedList@H@@QAEXPAH@Z) referenced in function _main
  1&gt;main.obj : error LNK2019: unresolved external symbol "public: __thiscall LinkedList&lt;int&gt;::LinkedList&lt;int&gt;(void)" (??0?$LinkedList@H@@QAE@XZ) referenced in function _main
  </code></pre>
  
  <p><strong>Attempted Solution:</strong></p>
  
  <p>I called <strong>LinkedListmyList()</strong> instead. This can resolve the linker error, but I will not be able to call any member function. </p>
  
  <p>myList.insert(ptrA) will say "Error: Expression must have a class type" if I put ().</p>
  
  <p>So clearly this is not working. </p>
  
  <p>What's the problem? I think the whole implementation has problems.... </p>
  
  <p>Thanks for your time.</p>