title: Define Only Non-Trivial Copy Operations
body: <p>I have a templated class which has many member variables. A small number of these variables have the template type of the class, the majority have fixed types.</p>
  
  <p>I'd like to copy between one instance of the class to another with conversions, but cannot do so using implicit copy if the classes do not have the same type. Therefore, I need an assignment method.</p>
  
  <p>However, it feels unfortunate to have to write out all of those many copy operations just to do the conversion I want.</p>
  
  <p>Therefore, <strong>is there a way to set up the assignment operator such that implicit copies are done where possible?</strong></p>
  
  <p>An example code follows:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  template&lt;class T&gt;
  class MyClass {
   public:
    int a,b,c,d,f; //Many, many variables
  
    T uhoh;        //A single, templated variable
  
    template&lt;class U&gt;
    MyClass&lt;T&gt;&amp; operator=(const MyClass&lt;U&gt;&amp; o){
      a    = o.a; //Many, many copy operations which
      b    = o.b; //could otherwise be done implicitly
      c    = o.c;
      d    = o.d;
      f    = o.f;
      uhoh = (T)o.uhoh; //A single converting copy
      return *this;
    }
  };
  
  int main(){
    MyClass&lt;int&gt; a,b;
    MyClass&lt;float&gt; c;
    a.uhoh = 3;
    b      = a; //This could be done implicitly
    std::cout&lt;&lt;b.uhoh&lt;&lt;std::endl;
    c = a;      //This cannot be done implicitly
    std::cout&lt;&lt;c.uhoh&lt;&lt;std::endl;
  }
  </code></pre>