title: Copy constructor called instead of Operator=
body: <p>I’m trying to do a simple exercise now with a Matrix and I want to implement this operations: Matrix a, Matrix b, Matrix c(a), Matrix d = a, Matrix e = a + b. For the moment I keep it simple but later I want to do the same thing, but with dynamic allocation and later with smart pointers. </p>
  
  <p>I declared an explicit copy constructor and I overloaded operator=, I also declared a destructor so I have the rule of three. </p>
  
  <p>Here are my functions:</p>
  
  <pre><code>Matrix&amp; Matrix::operator=(const Matrix&amp; opEven)
  {
      std::cout &lt;&lt; "Operator = " &lt;&lt; std::endl;
      for (int i = 0; i &lt; ORD; i++)
      {
          for (int j = 0; j &lt; ORD; j++)
          {
              arr1[i][j] = opEven.arr1[i][j];
          }
      }
  
      return *this;
  }
  
  Matrix::Matrix(const Matrix&amp; obj) 
  {
      std::cout &lt;&lt; "Constructing matrix using copy c-tor." &lt;&lt; std::endl;
      for (int i = 0; i &lt; ORD; i++)
      {
          for (int j = 0; j &lt; ORD; j++)
          {
              arr1[i][j] = obj.arr1[i][j];
          }
      }
  }
  </code></pre>
  
  <p>The problem is that, when I try to use Matrix d = a my compiler use the copy constructor, not my operator=.</p>
  
  <p><a href="https://i.stack.imgur.com/1WCGu.jpg" rel="nofollow noreferrer">Output:</a></p>