title: Assignement and addition overload for template objects
body: <p>I am trying to learn templates and overloads at the same time. I have wrote the code below but I fail to do assignement of the data object with built-in types. What am I dooing wrong and how to solve it and yet better what is the best practice that can result in no intemediate-copy constructors to be called?</p>
  <p>I want to have all the possible arithmetic operations. I think if I get it right for one of them (e.g. +) then others would be the same principles.</p>
  <p>Do I need Copy/Move constructor and assignements?</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;concepts&gt;
  
  template&lt;typename T&gt;
  requires std::is_arithmetic_v&lt;T&gt;
  class Data {
      private :
      T d;
      
      public: 
      Data(const T&amp; data) : d{data}{
          std::cout &lt;&lt; &quot;Constructed Data with: &quot; &lt;&lt; d &lt;&lt; std::endl;
      }
      Data(const Data&amp; other) = default;
      ~Data() {
          std::cout &lt;&lt; &quot;Destructed: &quot; &lt;&lt; d &lt;&lt; std::endl;
      }
  
      void operator+(const T&amp; other) {
          this-&gt;d += other;
      }
  
      Data operator+(const Data&amp; other) {
          return (this-&gt;d + other.d);
      }
  
      Data operator=(const Data&amp; other) {
          return(Data(d + other.d));
      }
  
      void operator=(const T&amp; t) {
          this-&gt;d += t;
      }
  
      Data operator=(const T&amp; t) { // FAIL
          return Data(this-&gt;d + t);
      }
  };
  
  int main() {
  
  Data a = 1;
  Data b = 2;
  
  Data c = a + b;
  Data d = 10;
  d = c + 1; // how to do this? FAIL
  
  }
  </code></pre>
  <p><a href="https://godbolt.org/z/drEYr5bs7" rel="nofollow noreferrer">Compile Explorer Link</a></p>