title: Overloading operator* for a matrix class
body: <p>I have a matrix:</p>
  
  <pre><code>#ifndef MATRIX_H
  #define MATRIX_H
  
  class Matrix
  {   
      public:
          Matrix(int rows, int columns);
          Matrix(int, int, int** matrix); 
          Matrix(Matrix* copy);
          ~Matrix();
  
          void Set(int, int, int);
          void SetMatrix(int, int, int** matrix);             
          void Print();
          void ZeroMatrix(int,int,int** matrix);      
          void Add(Matrix* B);
          void Subtract(Matrix* B);
          void Copy(Matrix* B);
  
          int** Multiply(Matrix* B);
          int** Create(int,int);
          int** Get();
          int** Transpose();
          int** Scalar(int);
  
          int Get(int,int);
          int Rows();
          int Columns();
  
          Matrix operator*(int);
  
      private:
          int** _matrix;
          int _rows;
          int _columns;
  };
  
  #endif
  </code></pre>
  
  <p>Here's the implementation:</p>
  
  <pre><code>Matrix Matrix::operator*(int scale)
  {
      return Matrix(_rows, _columns, Scalar(scale));
  }
  </code></pre>
  
  <p>And for a school assignment we have to overload the multiple operator to work with integer scalar. The problem is I keep getting this error:</p>
  
  <p>main.cpp: In function ‘int main(int, char*<em>)’:
  main.cpp:18:15: error: no match for ‘operator</em>’ in ‘4 * B’</p>
  
  <p>Breaking code:</p>
  
  <pre><code>#include "Matrix.h"
  #include &lt;fstream&gt;
  #include &lt;iostream&gt;
  
  int main(int argc, char *argv[])
  {   
      Matrix* A = new Matrix(4,2);
  
      A-&gt;Set(0,0,1);  
      A-&gt;Set(0,1,2);
      A-&gt;Set(1,0,3);
      A-&gt;Set(1,1,4);  
      A-&gt;Print();
  
      Matrix B(A);
      B.Print();
  
      Matrix C(4 * B); //this line
      C.Print();
  
  
      delete A;
  
      return 0;
  }
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>edit # 1:</p>
  
  <p>the code:</p>
  
  <pre><code>Matrix operator*(int); 
          Matrix operator* (int, const Matrix &amp;);
  </code></pre>
  
  <p>generates:</p>
  
  <pre><code>In file included from main.cpp:1:0:
  Matrix.h:31:40: error: ‘Matrix Matrix::operator*(int, const Matrix&amp;)’ must take either zero or one argument
  In file included from matrix.cpp:1:0:
  Matrix.h:31:40: error: ‘Matrix Matrix::operator*(int, const Matrix&amp;)’ must take either zero or one argument
  matrix.cpp:207:50: error: ‘Matrix Matrix::operator*(int, const Matrix&amp;)’ must take either zero or one argument
  </code></pre>