title: Writing a copy constructor with singly linked lists?
body: <p>I'm writing a copy constructor that copies for example S to R; Set R(S);. S is a sorted singly linked list containing some ints (with a dummy node in the beginning).</p>
  
  <pre><code>Set::Set (const Set &amp;source)
  {
  
      Node* sourceNode = source.head-&gt;next;
      head = new Node(0, nullptr);
      Node* nodeHead = source.head-&gt;next;
      Node* p;
  
  
      if (!sourceNode) {
          std::cout &lt;&lt; "Empty !" &lt;&lt; endl;
      }
      else{
      while (nodeHead) {
          for (p=sourceNode; p-&gt;next; p=p-&gt;next) {
              ;
          }
          head-&gt;next = new Node(nodeHead-&gt;value,nullptr);
          head = head-&gt;next;
  
          nodeHead = nodeHead-&gt;next;
  
          }
      }
  }
  </code></pre>
  
  <p>Right now it crashes and if i remove head = head->next; it will set S to { 5 }.</p>
  
  <p>This is the constructor:</p>
  
  <pre><code>class Node
  {
      public:
         Node (int, Node*);
  
      private:
         int value;
         Node* next;
  };
  </code></pre>
  
  <p>Why doesn't this work? This is my first experience with pointers so keep that in mind please.</p>