title: C++ overloaded operator= does not work properly
body: <p>I'm developing a custom Queue List class in C++.<br>
  In my main I have:</p>
  <pre><code>  QueueLst&lt;int&gt; q1;
    q1.Enqueue(1);
    q1.Enqueue(2);
    q1.Enqueue(3);
    cout&lt;&lt;q1.HeadAndDequeue()&lt;&lt;&quot; &quot;&lt;&lt;q1.HeadAndDequeue()&lt;&lt;&quot; &quot;&lt;&lt;q1.HeadAndDequeue();
  </code></pre>
  <p>that works fine, result:</p>
  <pre><code>1 2 3
  </code></pre>
  <p>Now if I write;</p>
  <pre><code>  QueueLst&lt;int&gt; q1;
    q1.Enqueue(1);
    q1.Enqueue(2);
    q1.Enqueue(3);
    QueueLst&lt;int&gt; q2;
    q2 = q1;
    cout&lt;&lt;q2.HeadAndDequeue()&lt;&lt;&quot; &quot;&lt;&lt;q2.HeadAndDequeue()&lt;&lt;&quot; &quot;&lt;&lt;q2.HeadAndDequeue();
  </code></pre>
  <p>output:</p>
  <pre><code>1
  terminate called after throwing an instance of 'std::length_error'
    what():  List is empty!
  </code></pre>
  <p>And this is my <code>operator=</code> method:</p>
  <pre><code>template &lt;typename Data&gt;
  QueueLst&lt;Data&gt;&amp; QueueLst&lt;Data&gt;::operator=(const QueueLst&amp; toCopy){
     QueueLst&lt;Data&gt;* tmp = new QueueLst&lt;Data&gt;(toCopy);
     std::swap(*this, *tmp);
     delete tmp;
     return *this;
  }
  </code></pre>
  <p>And I'm 100% sure the copy consructor works fine, in fact, if I write</p>
  <pre><code>template &lt;typename Data&gt;
  QueueLst&lt;Data&gt;&amp; QueueLst&lt;Data&gt;::operator=(const QueueLst&amp; toCopy){
     QueueLst&lt;Data&gt;* tmp = new QueueLst&lt;Data&gt;(toCopy);
     return *tmp;
  }
  </code></pre>
  <p>It works fine! So there is something strange in the std::swap but how?
  I'm sorry that this is a very specific question but can't figure out how to fix that, thank you.
  <br>
  <strong>Update</strong>
  Definition of QueueLst:</p>
  <pre><code>#include &quot;../queue.hpp&quot;
  #include &quot;../../list/list.hpp&quot;
  
  namespace lasd {
  
  template &lt;typename Data&gt;
  class QueueLst :  virtual public Queue&lt;Data&gt;,
                    virtual protected List&lt;Data&gt;{ // Must extend Queue&lt;Data&gt; and List&lt;Data&gt;
  
  private:
  
  protected:
  
    using List&lt;Data&gt;::head;
    using List&lt;Data&gt;::tail;
    using List&lt;Data&gt;::size;
    using typename List&lt;Data&gt;::Node;
  
  public:
  
    // Default constructor
    QueueLst() = default;
  
  
    // Specific constructor
    QueueLst(const LinearContainer&lt;Data&gt;&amp;); // A queue obtained from a LinearContainer
  
  
    // Copy constructor
    QueueLst(const QueueLst&amp;);
  
    // Move constructor
    QueueLst(QueueLst&amp;&amp;) noexcept;
  
  
    // Destructor
    ~QueueLst();
  
  
    // Copy assignment
    QueueLst&amp; operator=(const QueueLst&amp;);
  
    // Move assignment
    QueueLst&amp; operator=(QueueLst&amp;&amp;) noexcept;
  
  
    // Comparison operators
    bool operator==(const QueueLst&amp;) const noexcept;
    bool operator!=(const QueueLst&amp;) const noexcept;
  
  
    // Specific member functions (inherited from Queue)
  
    void Enqueue(const Data&amp;) override; // Override Queue member (copy of the value)
    void Enqueue(Data&amp;&amp;) override; // Override Queue member (move of the value)
    Data&amp; Head() const override; // Override Queue member (must throw std::length_error when empty)
    void Dequeue() override; // Override Queue member (must throw std::length_error when empty)
    Data HeadNDequeue() override; // Override Queue member (must throw std::length_error when empty)
  
  
    // Specific member functions (inherited from Container)
  
    void Clear() override; // Override Container member
  
  };
  
  }
  
  #include &quot;queuelst.cpp&quot;
  
  #endif
  </code></pre>