title: Deep copy of a queue using assignment operator
body: <p>I have troubles with the pointers using my assignment opperator, it doesn't make a new qeueu, instead the new array points to the old one. So when I delete in the new queue the values in my old queue changes.</p>
  
  <p>First off all I can see that my copy constructor isn't called in my main for some unknown reason, the problem is probably related with that. </p>
  
  <p>Some of my main code used to illustrate the problem: </p>
  
  <pre><code>aQueue.enqueue(10);
      aQueue.enqueue(20);
  
      Queue&lt;int&gt; cQueue = aQueue;             
  
      cout &lt;&lt; "aQueue: "; aQueue.printQeueue(2, 0);
      cout &lt;&lt; "cQueue: "; cQueue.printQeueue(3, 0);
  
      cQueue.dequeue();
      cout &lt;&lt; "aQueue: "; aQueue.printQeueue(4, 1);
      cout &lt;&lt; "cQueue: "; cQueue.printQeueue(5, 1);
      system("pause 4");
  </code></pre>
  
  <p>This is where the problems start, if I enqueue aQueue with 10 and 20 and then assign cQueue to aQueue, if I print aQueue the result is: 10 20. After that dequeue cQueue and print aQueue the result is: -179016023. If I print cQueue the result is: 20, as it should be.</p>
  
  <p>The output: <a href="http://imgur.com/XBaSXAT" rel="nofollow">http://imgur.com/XBaSXAT</a></p>
  
  <p>Here follows the functions used direct or indirect:</p>
  
  <pre><code>template &lt;typename T&gt;
  T Queue&lt;T&gt;::dequeue(){
  
      T temp = front();
  
      Node *old = fronten;
      fronten = fronten-&gt;next;
  
      delete old;
  
      return temp;
  
  }
  
  
  template &lt;typename T&gt;
  Queue&lt;T&gt;::Queue(const T &amp;rhs){
  
      Node *tempfront = rhs.fronten;
  
      while (tempfront.fronten!=rhs.back){
          enqueue(tempfront);
          tempfront = tempfront-&gt;next;
  
  
      }
  }
  
  template &lt;typename T&gt;
  void Queue&lt;T&gt;::enqueue(const T&amp; item){
  
  
      if (isEmpty()){
          back = fronten = new Node(item);
      }
      else
          back = back-&gt;next = new Node(item);
  }
  
  Node(const T &amp;theElement, Node *n = nullptr): element(theElement), next(n) {};
  </code></pre>