title: The head pointer won't stay in the front (C++)
body: <p>I'm trying to create a linked list, I have a Node class and a List class.  The list constructor sets Head and Tail (of type Node*) to nullptr.  Both classes are templatized.  My insert method for the list won't keep the head pointer pointed at the beginning and I'm really not sure why.  It's only assigned once when head == nullptr.</p>
  
  <p>Here is the insert method.</p>
  
  <pre><code>void insert(T item)
      {
        //insert item at end
        //allocate new node
        Node&lt;T&gt; tempNode = Node&lt;T&gt;(item);
        Node&lt;T&gt; *temp = &amp;tempNode;
        //put in data
        temp-&gt;setData(item);
        //end of list set to null
        temp-&gt;setNext(nullptr); 
  
        //if first node
        if (head == nullptr)
        {
          //head and tail are set to temp
          head = temp;
          cout &lt;&lt; "head1: " &lt;&lt; head-&gt;getData() &lt;&lt; endl;
          tail = temp;
        } else //not first node in list
        { cout &lt;&lt; "head: " &lt;&lt; head-&gt;getData() &lt;&lt; endl;
          tail-&gt;setNext(temp);
          tail = temp;
        }
  
        cout &lt;&lt; "tail: " &lt;&lt; tail-&gt;getData() &lt;&lt; endl;
        cout &lt;&lt; "head: " &lt;&lt; head-&gt;getData() &lt;&lt; endl;
        cout &lt;&lt; "head: " &lt;&lt; head &lt;&lt; endl;
      }
  </code></pre>
  
  <p>the cout is just for me to see what's going on.  Every <code>head-&gt;getData()</code> Produces the value currently held in temp however when I print head it is the same address every time.</p>
  
  <p>just to be clear I have a separate test file that loops 0-9 attempting insert with each value.  The results of that are...</p>
  
  <pre><code>head1: 0
  tail: 0
  head: 0
  head: 0x7fffc574dc40
  head: 1
  tail: 1
  head: 1
  head: 0x7fffc574dc40
  head: 2
  tail: 2
  head: 2
  head: 0x7fffc574dc40
  head: 3
  tail: 3
  head: 3
  head: 0x7fffc574dc40
  head: 4
  tail: 4
  head: 4
  head: 0x7fffc574dc40
  head: 5
  tail: 5
  head: 5
  head: 0x7fffc574dc40
  head: 6
  tail: 6
  head: 6
  head: 0x7fffc574dc40
  head: 7
  tail: 7
  head: 7
  head: 0x7fffc574dc40
  head: 8
  tail: 8
  head: 8
  head: 0x7fffc574dc40
  head: 9
  tail: 9
  head: 9
  head: 0x7fffc574dc40
  </code></pre>