title: How to properly implement assignment operator between two child-classes
body: <p>Let's say I have an abstract class <code>Parent</code> and classes <code>Child1</code> and <code>Child2</code> that both inherit from it.
  Now I need to properly implement an assignment operator between <code>Child1</code> and <code>Child2</code>.</p>
  
  <p>The problem that immediately arises is that I cannot define an operator of form</p>
  
  <pre><code>Child1 operator=(const Child2 &amp; rhs);
  </code></pre>
  
  <p>because this requires the class <code>Child2</code>to be completely defined at the point of the operators definition and the same for the operator defined in <code>Child 2</code>.</p>
  
  <p>I tried defining the operator as </p>
  
  <pre><code>Child1 operator=(const Parent &amp; rhs);
  </code></pre>
  
  <p>And that seemed to work in most of the cases, but failed in case of the following:</p>
  
  <pre><code>vector&lt;Parent *&gt; children;
  children.push_back(new Child1());
  children.push_back(new Child2());
  
  (*children[1]) = *const_cast&lt;const Parent *&gt;(children[0]);
  </code></pre>
  
  <p>In this case compiler wanted to run the assignment operator</p>
  
  <pre><code>Parent operator=(const Parent &amp;) 
  </code></pre>
  
  <p>which I cannot implement because the compiler won't let me define a return type which is an abstract class. </p>
  
  <p>So how do you do this properly?</p>