title: error C2676 when compiling
body: <p>I'm trying to write code in C++ (using template) to add between 2 matrices.</p>
  
  <p>I have the following code in .h file.</p>
  
  <pre><code>#ifndef __MATRIX_H__
  #define __MATRIX_H__
  
  //***************************
  //         matrix
  //***************************
  
  template &lt;class T, int rows, int cols&gt; class matrix {
  public:
      T mat[rows][cols];
      matrix();
      matrix(T _mat[rows][cols]);
      matrix operator+(const matrix&amp; b);
  };
  
  template &lt;class T, int rows, int cols&gt; matrix &lt;T,rows,cols&gt; :: matrix (T _mat[rows][cols]){
      for (int i=0; i&lt;rows; i++){
          for (int j=0; j&lt;cols; j++){
              mat[i][j] = _mat[i][j];
          }
      }
  }
  
  template &lt;class T, int rows, int cols&gt; matrix &lt;T,rows,cols&gt; :: matrix (){
      for (int i=0; i&lt;rows; i++){
          for (int j=0; j&lt;cols; j++){
              mat[i][j] = 0;
          }
      }
  }
  
  template &lt;class T, int rows, int cols&gt; matrix &lt;T,rows,cols&gt; matrix &lt;T,rows,cols&gt;::operator+(const matrix&lt;T, rows, cols&gt;&amp; b){
      matrix&lt;T, rows, cols&gt; tmp;
      for (int i=0; i&lt;rows; i++){
          for (int j=0; j&lt;cols; j++){
              tmp[i][j] = this-&gt;mat[i][j] + b.mat[i][j];
          }
      }
      return tmp;
  }
  
  
  
  #endif
  </code></pre>
  
  <p>my .cpp :</p>
  
  <pre><code>#include "tar5_matrix.h"
  int main(){
  
      int mat1[2][2] = {1,2,3,4};
      int mat2[2][2] = {5,6,7,8};
      matrix&lt;int, 2, 2&gt; C;
      matrix&lt;int, 2, 2&gt; A = mat1;
      matrix&lt;int, 2, 2&gt; B = mat2;
      C = A+B;
      return 0;
  }
  </code></pre>
  
  <p>When compiling, I get the following error:</p>
  
  <blockquote>
    <p>1>c:\users\karin\desktop\lior\study\cpp\cpp_project\cpp_project\tar5_matrix.h(36):
    error C2676: binary '[' : 'matrix' does not define this
    operator or a conversion to a type acceptable to the predefined
    operator</p>
  </blockquote>
  
  <p>Please advise</p>