title: Overload operators += and + Matrix c++
body: <p>I'm having problems with overloading operators += and + in c++. I've got the following and I don't know why.. : "Invalid operands to binary expression (Matrice* and Matrice*) Do you have any ideas why ? Thanks. </p>
  
  <p>NB : operator = does work. </p>
  
  <h1>main.cpp</h1>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cmath&gt;
  using namespace std ;
  #include "Matrice.hpp"
  
  
  int main () {
  
  double *tableau = new double[2*2]{1,4,3,2} ;
  double *tableau1 = new double[2*2]{1,6,4,-2} ;
  Matrice * A = new Matrice(2, tableau) ;
  Matrice * B = new Matrice(2, tableau1) ;
  Matrice * C = new Matrice() ;
  
  C = A+B ;} // error appears here
  </code></pre>
  
  <h1>Matrice.cpp</h1>
  
  <pre><code>#include "Matrice.hpp"
  
  Matrice::Matrice(const Matrice&amp; m) : dim(m.dim), coeffs(new         double[m.dim*m.dim]){
  for(int i=0; i&lt;dim*dim; i++) {
      coeffs[i] = m.coeffs[i] ; 
  }
  
  }
  
  Matrice::~Matrice() {
  delete [] coeffs ;
  }
  </code></pre>
  
  <h1>Matrice.hpp</h1>
  
  <pre><code>#ifndef Matrice_hpp
  #define Matrice_hpp
  
  #include &lt;iostream&gt;
  using namespace std ;
  
  class Matrice {
  private :
  unsigned int dim;
  double * coeffs ;
  
  public :
  Matrice() {
      dim = 2 ;
      coeffs = new double[dim*dim] ;
      for(int i=0; i&lt;dim*dim; i++) {
          coeffs[i] = 0 ;
      }
  }
  
  
  Matrice(unsigned int n, double* v) : dim(n), coeffs(new double[dim*dim]) {
      if(v) { for(int i=0; i&lt;dim*dim; i++) { coeffs[i] = v[i] ;}
      }
      else { for(int i=0; i&lt;dim*dim; i++) coeffs[i] = 0 ; }
  }
  
  Matrice(const Matrice&amp;) ;
  ~Matrice () ;
  
  int dimension() const {return dim;}
  void modifier(int position, int valeur) {coeffs[position] = valeur ; }
  
  
  Matrice&amp; operator= (const Matrice&amp; m) {
      if(coeffs != m.coeffs) {
          delete [] coeffs ;
          dim = m.dim ;
          coeffs = new double[m.dim*m.dim] ;
          for(int i=0; i&lt;m.dim*m.dim ; i++) {
              coeffs[i] = m.coeffs[i] ;
          }
      }
  
      return *this ;
  }
  
  
  
  Matrice&amp; operator+=(const Matrice&amp; m) {
      for(int i=0; i&lt;dim*dim; i++) {
          coeffs[i] += m.coeffs[i] ;
      }
  
      return *this ;
  }
  
  Matrice&amp;operator+ (const Matrice&amp; m)
  {
  
      for(int i=0; i&lt;dim*dim; i++) {
          coeffs[i] = coeffs[i] + m.coeffs[i] ;
      }
      return *this ;
  }
  
  
  
  double* Coefficients() {return coeffs ;}
  void Afficher() {
      for(int i=0; i&lt;dim*dim; i++) {
          if (i%dim == 0) {cout &lt;&lt; endl ; }
          cout &lt;&lt; coeffs[i] &lt;&lt; " "  ;
      }
      cout &lt;&lt; endl ; 
  }
  
  
  };
  
  
  #endif /* Matrice_hpp */
  </code></pre>