title: Inserting at the tail of a doubly linked list
body: <p>I'm working with linked lists for my first time and have to create a function that can insert a node at the end of a doubly linked list. So far I have</p>
  
  <pre><code>void LinkedList::insertAtTail(const value_type&amp; entry) {
      Node *newNode = new Node(entry, NULL, tail);
      tail-&gt;next = newNode;
      tail = newNode;
      ++node_count;
  }
  </code></pre>
  
  <p>The Node class accepts a value to be stored, a value for the next pointer to point to, and a value for the previous pointer in that order. Whenever I try to insert a node here, I get an error saying there was an unhandled exception and there was an access violation in writing to location 0x00000008.</p>
  
  <p>I'm not entirely sure what's going wrong here but I assume it has something to do with dereferencing a null pointer based on the error message. I would really appreciate some help with solving this problem.</p>
  
  <p>EDIT:</p>
  
  <p>I should have clarified early, tail is a pointer that points to the last node in the list. Tail->next accesses the next variable of that last node which, before the function runs, points to NULL but after it executes should point to the new node created.</p>