title: Template assignment operator overloading mystery
body: <p>I have a simple struct <code>Wrapper</code>, distinguished by two templated assignment operator overloads:</p>
  
  <pre><code>template&lt;typename T&gt;
  struct Wrapper {
  
    Wrapper() {}
  
    template &lt;typename U&gt;
    Wrapper &amp;operator=(const Wrapper&lt;U&gt; &amp;rhs) {
      cout &lt;&lt; "1" &lt;&lt; endl;
      return *this;
    }
    template &lt;typename U&gt;
    Wrapper &amp;operator=(Wrapper&lt;U&gt; &amp;rhs) {
      cout &lt;&lt; "2" &lt;&lt; endl;
      return *this;
    }
  };
  </code></pre>
  
  <p>I then declare a and b:</p>
  
  <pre><code>Wrapper&lt;float&gt; a, b;
  a = b;
  </code></pre>
  
  <p>assigning <code>b</code> to <code>a</code> will use the non-const templated assignment operator overload from above, and the number "2" is displayed.</p>
  
  <p>What puzzles me is this: If I declare <code>c</code> and <code>d</code>,</p>
  
  <pre><code>Wrapper&lt;float&gt; c;
  const Wrapper&lt;float&gt; d;
  c = d;
  </code></pre>
  
  <p>and assign <code>d</code> to <code>c</code>, neither of the two assignment operator overloads is used, and no output is displayed; so the default copy assignment operator is invoked. Why does assigning <code>d</code> to <code>c</code> not use the const overloaded assignment operator provided? Or instead, why does assigning <code>b</code> to <code>a</code> <em>not</em> use the default copy assignment operator?</p>