title: Linked list copy constructor
body: <p>I originally had to create my own linked list with using the STL. Now, I am to implement a copy constructor method and I am having real difficulty understanding it. Have a test on this in a few days so I would really like to get it clear. (Test is closed book so need to really).
  The List contains a EmployeeNode pointer *head. The EmployeeNode contains an Employee and a pointer to the next EmployeeNode. The Employee class contains a name and salary.</p>
  
  <p>The method seems to get caught in the for loop when trying to copy the 3rd node over. I think this is because I overwrite the newNode but I do not know how to solve this.</p>
  
  <pre><code>ListOfEmployee::ListOfEmployee(const ListOfEmployee &amp;obj)
  {
      head = NULL;
  
      if(obj.head != NULL)
      {
          EmployeeNode *newNode  = new EmployeeNode("", 0);
          EmployeeNode *tempPtr;
          EmployeeNode *newPtr;
  
          //using the temp pointer to scroll through the list until it reaches the end
          for(tempPtr = obj.head; tempPtr-&gt;next !=NULL; tempPtr = tempPtr-&gt;next)
          {
              if(head == NULL)
              {
                  cout&lt;&lt;"Attempts to initialize the head"&lt;&lt;endl;
  
                  head = newNode; //assinging the new node to the head
                  newNode-&gt;emp.name = tempPtr-&gt;emp.name;
                  newNode-&gt;emp.salary = tempPtr-&gt;emp.salary;
  
                  cout&lt;&lt;"Initializes the head"&lt;&lt;endl;
              }
              else
              {
                  cout&lt;&lt;"Attempts to add a new node"&lt;&lt;endl;
  
                  //using the temp pointer to scroll through the list until it reaches the end
                  for(newPtr = head; newPtr-&gt;next !=NULL; newPtr = newPtr-&gt;next)
                  {
                      cout&lt;&lt;"Looping through the list"&lt;&lt;endl;
                  }
  
                  //assiging the last place to the new node
                  newPtr-&gt;next = newNode;
                  newNode-&gt;emp.name = tempPtr-&gt;emp.name;
                  newNode-&gt;emp.salary = tempPtr-&gt;emp.salary;
  
                  cout&lt;&lt;"Adds a new node"&lt;&lt;endl;
              }
          }
      }
  }
  </code></pre>