title: C++ Error with trying to overload operators and use class template
body: <p>My code doesnt compile and I'm really confused.When I run the code I get an error in the header file that says "Declaration of 'T' shadows template parameter. My teacher told us in class to put template prefix template before declaration of the operators inside a class definition. I don't know if she's wrong or not but I tried removing the template that were above the declaration of friend functions and when i tried compiling the code i get some errors that have linker Id issues. One of them refers to Matrix::Matrix(int). Honestly I still think what my teacher said about putting the template prefix above the declaration of the operator is right because the operators have the class type in their parameter but can someone help me out!</p>
  
  <p>In my header file I have:</p>
  
  <pre><code>#ifndef __testing_more_stuff__vector__
  #define __testing_more_stuff__vector__
  
  #include&lt;iostream&gt;
  #include&lt;fstream&gt;
  using namespace std;
  template &lt;class T&gt;
  class Matrix{
  public:
      Matrix();
      Matrix(T diagonal);
  
      //template &lt;class T&gt;
      friend ostream&amp; operator &lt;&lt;(ostream&amp; outs, const Matrix&lt;T&gt; &amp;obj);
      //template &lt;class T&gt;
      friend istream&amp; operator &gt;&gt;(istream&amp; in, Matrix&lt;T&gt; &amp;obj);
      //template &lt;class T&gt;
      friend Matrix&lt;T&gt; operator *(Matrix&lt;T&gt; A, Matrix&lt;T&gt; B);
  
  private:
      const static int n=3;
      T a[n][n];
  
  
  };//class declaration
  
  #endif
  </code></pre>
  
  <p>In my implementation file I have:</p>
  
  <pre><code>#include "vector.h"
  
  template &lt;class T&gt;
  Matrix&lt;T&gt;::Matrix(){
      for (int i=0;i&lt;n;i++)
          for (int j=0;j&lt;n;j++)
              a[i][j]=0;
  }
  template &lt;class T&gt;
  Matrix&lt;T&gt;::Matrix(T diagonal){
      for (int i=0;i&lt;n;i++)
          for (int j=0;j&lt;n;j++)
              if (i==j)
                  a[i][j]=diagonal;
              else
                  a[i][j]=0;
  }
  template &lt;class T&gt;
  ostream&amp; operator &lt;&lt;(ostream&amp; outs, const Matrix&lt;T&gt; &amp; obj)
  {
      for (int i = 0; i &lt; obj.n; i++){
          for (int j = 0; j &lt; obj.n; j++)
              outs &lt;&lt; " "&lt;&lt; obj.a[i][j];
          outs&lt;&lt;endl;
      }
      outs&lt;&lt;endl;
      return outs;
  }
  template &lt;class T&gt;
  istream&amp; operator &gt;&gt;(istream&amp; in, Matrix&lt;T&gt; &amp; obj)
  {
      for (int i = 0; i &lt; obj.n; i++){
          for (int j = 0; j &lt; obj.n; j++){
  
              in &gt;&gt; obj.a[i][j];
          }
      }
      return in;
  }
  template&lt;class T&gt;
  Matrix&lt;T&gt; operator *(Matrix&lt;T&gt; A, Matrix&lt;T&gt; B){
      Matrix&lt;T&gt; product;
      for (int i=0;i&lt;A.n; i++)
          for (int j=0;j&lt;A.n; j++) {
              T sum=0;
              for (int k=0; k&lt;A.n; k++)
                  sum = sum+A.a[i][k]*B.a[k][j];
              product.a[i][j]=sum;
          }
      return product;
  }
  </code></pre>
  
  <p>In my main file I have:</p>
  
  <pre><code>#include "vector.h"
  
  
  int main(){
      Matrix&lt;int&gt;  A;
      Matrix&lt;int&gt;  B(2);
      cout &lt;&lt; A;
      cout &lt;&lt;B;
  
      cout &lt;&lt;"stop here";
  
      ifstream fin;
      ofstream fout;
      fout.open("output.txt");
      if (fout.fail()){
          cout &lt;&lt;"error openning output file";
          exit(1);
      }
  
      fin.open("input.txt");
      if (fin.fail()){
          cout &lt;&lt;"error openning input file";
          exit(1);
      }
  
      //input matrix C
      Matrix&lt;int&gt; C;
      cin &gt;&gt;C;
      //fin &gt;&gt;C;
      cout &lt;&lt;"C = "&lt;&lt;endl&lt;&lt;C&lt;&lt;endl;
      cout &lt;&lt;"B = "&lt;&lt;endl&lt;&lt;B&lt;&lt;endl;
      cout &lt;&lt;"C*B = "&lt;&lt;endl&lt;&lt;C*B&lt;&lt;endl;
      //fout &lt;&lt;C;
      //cout &lt;&lt;C.det();
  
      return 0;
  
  }
  </code></pre>