title: Esoteric "Undefined Reference to" error with custom template LinkedList class
body: <p>I'm learning basic Linked Lists and wanted to try my hand at writing my own implementation. 
  However, I keep getting the following errors when compiling:</p>
  
  <pre><code>/tmp/ccNerPXr.o: In function `main':
  main.cpp:(.text+0x10): undefined reference to `LinkedList&lt;int&gt;::LinkedList()'
  main.cpp:(.text+0x2c): undefined reference to `LinkedList&lt;int&gt;::insert(int const&amp;)'
  main.cpp:(.text+0x49): undefined reference to `LinkedList&lt;int&gt;::displayList()'
  collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p>I've looked at other stack overflow answers and couldn't find one to meet my specific issue. The name of the template class matches the instance declaration in main, I remembered to #include "LinkedList.h" properly, and I double-checked to make sure the forward declarations in *.h matched the ones in *.cpp. What else could be causing this error? Is it staring me in the face, and I'm just too blind to see it?  I feel like this might be simpler than what I'm making it...</p>
  
  <p>Here is my (unfinished) source code for reference: 
  main.cpp </p>
  
  <pre><code>    #include "LinkedList.h"
  #include &lt;iostream&gt; 
  using namespace std; 
  
  int main() 
  { 
      LinkedList&lt;int&gt; normList;
      for(int i = 0; i &lt; 5; i++) 
          normList.insert(i);  
  
      normList.displayList(); 
  
      return 0; 
  } 
  </code></pre>
  
  <p>LinkedList.h </p>
  
  <pre><code>#ifndef LINKEDLIST_H
  #define LINKEDLIST_H
  #include &lt;cstddef&gt;   
  
  template &lt;class Object&gt;
  class LinkedList  
  { 
      struct ListNode
      { 
          Object element; 
          ListNode *next;
          ListNode() : element(0), next(NULL) {};      
      }; 
  
          ListNode *head; 
          ListNode *tail; 
  
      public: 
          LinkedList();   
          void insert(const Object &amp;x); 
          void erase(const Object &amp;x); 
          void eraseList(); 
          void displayList(); 
  
  }; 
  
  #endif 
  </code></pre>
  
  <p>LinkedList.cpp </p>
  
  <pre><code>#include "LinkedList.h" 
  #include &lt;iostream&gt; 
  using namespace std; 
  
  template &lt;class Object&gt;
  LinkedList&lt;Object&gt;::LinkedList()
  { 
      head = NULL; 
  }   
  
  /*This function will insert an object
  *using the tail-end insertion method
  *i.e., inserting at the end of the list  
  */
  
  template &lt;class Object&gt;
  void LinkedList&lt;Object&gt;::insert(const Object &amp;x) 
  {
      ListNode *newNode = new ListNode(x, NULL); 
  
      if( !head ) {  
         head = newNode;
         tail = head;  
      } else {  
         tail-&gt;next = newNode; 
         tail = newNode;          
      } 
  
  }//insert() 
  
  template &lt;class Object&gt;
  void LinkedList&lt;Object&gt;::erase(const Object &amp;x) 
  { 
      ListNode *prev; 
  
  
  } //erase()
  
  /*
  *Function that deletes entire list 
  */ 
  template &lt;class Object&gt; 
  void LinkedList&lt;Object&gt;::eraseList() 
  { 
      ListNode *prev;
      while(head-&gt;next) 
      {   
          prev = head; 
          delete head; 
          head = prev-&gt;next; 
      } 
  
  }//eraseList()
  
  template &lt;class Object&gt; 
  void LinkedList&lt;Object&gt;::displayList() 
  { 
      if(!head) 
          cout &lt;&lt; "The list is empty\n"; 
  
      while(head-&gt;next) 
      { 
          cout &lt;&lt; head-&gt;element &lt;&lt; endl; 
          head = head-&gt;next; 
      }   
  
  } //displayList() 
  </code></pre>
  
  <p>Thanks in advance to any help or input </p>