title: Trouble overloading operator >> for a matrix class
body: <p>I am trying to learn operator overloading by working on overloading >> for a matrix class to enable the key-board based input for a matrix by calling sth such as </p>
  
  <pre><code>Matrix M1;
  cin &gt;&gt; M1;
  </code></pre>
  
  <p>The operator overloading part is given in the following</p>
  
  <pre><code>istream &amp;operator&gt;&gt;(istream &amp;in, Matrix &amp;m) 
  {
      for (int i = 0; i &lt; m.dx; ++i)    {
          for (int j = 0; j &lt; m.dy; ++j)
              in &gt;&gt; m.p[i][j];
      }
      return in;
  }
  </code></pre>
  
  <p>It turns work that my implementation was not correct at all. Can you let me know why this implementation is wrong?</p>
  
  <p>I implemented the above part by imitating an existing implementation of overloading >>, which has been proven to work fine in the matrix output part, like  cout&lt;&lt; A; where A is a matrix</p>
  
  <pre><code>ostream &amp;operator&lt;&lt;(ostream &amp;out, const Matrix &amp;m) 
  {
      for (int i = 0; i &lt; m.dx; ++i)    {
          for (int j = 0; j &lt; m.dy; ++j)
              out &lt;&lt; m.p[i][j] &lt;&lt; "  ";
          out &lt;&lt; endl;
      }
      return out;
  }
  </code></pre>