title: C++ Linked Lists with Multi-Files
body: <p>I am a bit new to using multi-files. I have this very simple code for a linked list, but when I debug, it "stops working".</p>
  
  <p>This problem has occured with me several times before. I want to know is there something wrong with my "linked list" code? Or is something wrong with the multi-files organization?</p>
  
  <p>Any help would be highly appreciated.</p>
  
  <p>======================================</p>
  
  <pre><code>//linkedListMAIN.cpp
  
  #include "linkedlist.cpp"
  
  void main()
  {
  linkList&lt;int&gt; l;
  
  l.append(5);
  l.traverse();
  }
  </code></pre>
  
  <p>======================================</p>
  
  <pre><code>//linkedList.h    
  
  #include&lt;iostream&gt;
  using namespace std;
  
  template &lt;class T&gt;
  class linkList
  {
  private:
  struct node
  {
      T data;
      node *next;
  };
  node *head;
  node *tail;
  int noOfEl;
  public:
  linkList()
  {
      noOfEl = 0;
      head=tail=NULL;
  }
  
  void traverse();
  int length();
  void insertAt(T, int);
  T delAt(int);
  void append(T);
  void clear();
  };
  </code></pre>
  
  <p>======================================</p>
  
  <pre><code>//linkedList.cpp    
  #include "linkedlist.h"
  
  template &lt;class T&gt;
  void linkList&lt;T&gt;:: traverse()
  {
  node&lt;T&gt; *current=head;
  
  if(head == NULL)
  {
      cout&lt;&lt;"List empty."&lt;&lt;endl;
  }
  
  while(current != NULL)
  {
      cout&lt;&lt;current-&gt;data;
      current = current-&gt;next;
  }
  }
  
  
  template &lt;class T&gt;
  void linkList&lt;T&gt;::append(T data)
  {
  node&lt; *newNode= new node;
  
  newNode-&gt;next = NULL;
  tail-&gt;next = newNode;
  tail = newNode;
  
  noOfEl++;  
   }
  </code></pre>