title: C++ multiplication of 2 matrices
body: <p>I am trying to multiply 2 matrices with the overloaded * operator and print the result. Although seems like I cannot have more than 1 argument to the overloaded function. How do I pass the two matrices to the overloaded function? Please see my implementation below. </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include&lt;string&gt;
  #include &lt;vector&gt;
  using namespace std;
  
  
  
  class Class1
  {
  public:
      vector&lt;vector&lt;int&gt; &gt; matrix;
      vector&lt;vector&lt;int&gt; &gt;  tmp;
      Class1(vector&lt;vector&lt;int&gt; &gt; p):matrix(move(p)){}
  
      //This function is used to perform the multiplication operation between two square matrices
      void operator*(const Class1 &amp;mat1,const Class1 &amp;mat2)
       {
  
          for(int i=0;i&lt;4;i++)
          {
             for(int j=0;j&lt;4;j++)
             {
  //            matrix[i][j]=0;
                for(int k=0;k&lt;4;k++)
                {
                   tmp[i][j]=tmp[i][j]+(mat2.matrix[i][k]*mat1.matrix[k][j]);
                }
             }
          }
  //      return tmp;
       }
  
      void PrintVector()
      {
          for(int i=0;i&lt;4;i++)
          {
  
              for(int j=0;j&lt;4;j++)
              {
                  cout&lt;&lt;tmp[i][j]&lt;&lt;"  ";
              }
              cout&lt;&lt;endl;
          }
          cout&lt;&lt;endl;
      }
  
  };
  
  int main()
  {
      Class1 Matrix1 =   {{{ 21, 12, 13, 14 },
                         { 5, 6, 6, 8 },
                         { 9, 8, 7, 6 },
                         { 3, 2, 1, 1 } }};
  
      Class1 Matrix2 =   Matrix1;
  
  
      Class1 Matrix3 = Matrix1 * Matrix2;
  
      Matrix3.PrintVector();
  
      return 0;
  }
  </code></pre>