title: Matrix addition using operator overloading
body: <p>I ave made a program for matrix addition using operator overloading. I have made the program but it is not taking input for matrix B. Please look at the program and help. In this the matrix inputs are noramlly taken in main with two different objects, then i have used operator overloading for '+' to add 2 object members, ten for displaying also '&lt;&lt;' operator is overloaded.</p>
  
  <pre><code>    #include&lt;iostream&gt;
      using namespace std;
      int s;
      class matrix
      {
      public:
          int **m1,**m;
          friend matrix operator +(matrix &amp;t,matrix &amp;t1);
          friend ostream&amp; operator &lt;&lt; (ostream &amp;out,matrix &amp;t);
      };
      matrix operator +(matrix &amp;t,matrix &amp;t1)
      {
          for(int x=0;x&lt;s;x++)
          {
              for(int y=0;y&lt;s;y++)
              {
                  t.m1[x][y]+=t1.m1[x][y];
              }
          }
      }
      ostream&amp; operator &lt;&lt; (ostream &amp;out,matrix &amp;t2)
      {
          for(int p=0;p&lt;s;p++)
          {
              for(int q=0;q&lt;s;q++)
              {
                  out&lt;&lt;t2.m[p][q]&lt;&lt;"  ";
              }        
             out&lt;&lt;endl;
          }
      }
      int main()
      {
          cout&lt;&lt;"Enter the size of matrices(SQUARE MAT ONLY):: ";
          cin&gt;&gt;s;
          matrix t,t1,t2;
          for(int i=0;i&lt;s;i++)
          {
              for(int j=0;j&lt;s;j++)
              {
                  cout&lt;&lt;"Enter value ("&lt;&lt;i+1&lt;&lt;","&lt;&lt;j+1&lt;&lt;") for matrix A::";
                  cin&gt;&gt;t.m1[i][j];
              }
          }
          for(int i=0;i&lt;s;i++)
          {
              for(int j=0;j&lt;s;j++)
              {
                  cout&lt;&lt;"Enter value ("&lt;&lt;i+1&lt;&lt;","&lt;&lt;j+1&lt;&lt;") for matrix B::";
                  cin&gt;&gt;t1.m1[i][j];
              }
          }
          t2=t+t1;
          cout&lt;&lt;t2;
      }
  </code></pre>