title: Invalid Operands to binary Expression (C++ operator overload)
body: <p>I just implemented my own matrix class that has some functions, i wrote  <code>=</code> and <code>*</code> operator overload functions for copying and multiplying matrices, however when i run a test program i got the following error:</p>
  
  <blockquote>
    <blockquote>
      <p>Invalid Operands to binary Expression (Matrix4X4 and Matrix4X4)</p>
    </blockquote>
  </blockquote>
  
  <p>my main Code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "Matrix4X4.h"
  
  using namespace std;
  
  int main(int argc, const char * argv[])
  {
  
  Matrix4X4 mat(4);
  Matrix4X4 sat;
  Matrix4X4 result;
  
  sat.setTranslation(5, 2, 6);
  
  
  //////////// just printing code nothing worth looking for ///////////////////////////
  float * ptr = mat.getMat();
  
  for (int i = 0 ; i &lt; 16; i += 4)
      cout &lt;&lt; ptr[i] &lt;&lt; "   " &lt;&lt; ptr[i+1] &lt;&lt; "   " &lt;&lt; ptr[i+2] &lt;&lt; "   " &lt;&lt; ptr[i+3] &lt;&lt; endl;
  
  cout &lt;&lt; "\n\n\n" &lt;&lt; endl;
  
  ptr = sat.getMat();
  
  for (int i = 0 ; i &lt; 16; i += 4)
      cout &lt;&lt; ptr[i] &lt;&lt; "   " &lt;&lt; ptr[i+1] &lt;&lt; "   " &lt;&lt; ptr[i+2] &lt;&lt; "   " &lt;&lt; ptr[i+3]  &lt;&lt; endl;
  ////////////////////////////// end of printing code //////////////////////////////////////
  
  
  result = mat * sat;       //  &lt;&lt;&lt;&lt; line that generates the error.
  
  
  
  return 0;
  }
  </code></pre>
  
  <p>Matrix4X4.cpp file:</p>
  
  <pre><code>#include "Matrix4X4.h"
  
  
  Matrix4X4::Matrix4X4()
  {
  setIdentity();
  }
  
  Matrix4X4::Matrix4X4(float value)
  {
  for(int i = 0 ; i &lt; 4; i++)
      for ( int j = 0; j &lt; 4; j++)
          Matrix[i][j] = value;
  
  }
  
  
  Matrix4X4::~Matrix4X4()
  {
  
  }
  
  
  void Matrix4X4::setIdentity()
  {
  Matrix[0][0] =1;   Matrix[0][1] = 0;  Matrix[0][2] = 0;      Matrix[0][3] = 0;
  Matrix[1][0] =0;   Matrix[1][1] = 1;  Matrix[1][2] = 0;      Matrix[1][3] = 0;
  Matrix[2][0] =0;   Matrix[2][1] = 0;  Matrix[2][2] = 1;      Matrix[2][3] = 0;
  Matrix[3][0] =0;   Matrix[3][1] = 0;  Matrix[3][2] = 0;      Matrix[3][3] = 1;
  
  }
  
  
  void Matrix4X4::setTranslation(float x,float y,float z)
  {
  Matrix[0][0] =1;   Matrix[0][1] = 0;  Matrix[0][2] = 0;      Matrix[0][3] = x;
  Matrix[1][0] =0;   Matrix[1][1] = 1;  Matrix[1][2] = 0;      Matrix[1][3] = y;
  Matrix[2][0] =0;   Matrix[2][1] = 0;  Matrix[2][2] = 1;      Matrix[2][3] = z;
  Matrix[3][0] =0;   Matrix[3][1] = 0;  Matrix[3][2] = 0;      Matrix[3][3] = 1;
  
  }
  
  
  
  
  float * Matrix4X4::getMat()
  {
  return (float *) Matrix;
  }
  
  
  float Matrix4X4::getMember(int x, int y)
  {
  return Matrix[x][y];
  }
  
  
  void Matrix4X4::setMat(int row,int col,float value)
  {
  Matrix[row][col] = value;
  }
  
  
  
  
  Matrix4X4 operator * (Matrix4X4 &amp; lhs,Matrix4X4 &amp; rhs)
  {
  
  Matrix4X4 result;
  
      for(int i = 0 ; i &lt; 4; i++)
          for ( int j = 0; j &lt; 4; j++)
              result.setMat(i, j,  lhs.getMember(i,0) * rhs.getMember(0, j) +
                              lhs.getMember(i,1) * rhs.getMember(1, j) +
                              lhs.getMember(i,2) * rhs.getMember(2, j) +
                              lhs.getMember(i,3) * rhs.getMember(3, j));
  
  
          return result;
  }
  </code></pre>
  
  <p>Matrix4X4.h file:</p>
  
  <pre><code>#ifndef ___D_GameDev_Kit__Matrix4X4__
  #define ___D_GameDev_Kit__Matrix4X4__
  
  #include &lt;iostream&gt;
  
  
  
  
  
  
  
  class Matrix4X4
  {
  private:
  float  Matrix[4][4];
  
  public:
  
  Matrix4X4();
  Matrix4X4(float);
  ~Matrix4X4();
  
  
  void setIdentity();
  void setTranslation(float,float,float);
  void setRotation();
  void setScale(float,float,float);
  void setPerspective();
  void setOrthogonal();
  
  float * getMat();
  float getMember(int,int);
  void setMat(int,int,float);
  
  
  
  Matrix4X4 &amp; operator = (Matrix4X4 &amp; rhs)
  {
      if(this!=&amp;rhs)
          for(int i = 0 ; i &lt; 4; i++)
              for (int j = 0; j &lt; 4; j++)
                  Matrix[j][i] = rhs.getMember(j, i);
                  return *this;
  }
  };
  
  
  #endif /* defined(___D_GameDev_Kit__Matrix4X4__) */
  </code></pre>