title: Operator overloading with friend function error
body: <p>I am working on an assignment that introduces me to operator overloading. I have to overload some binary operators as member functions and also as friend functions. My member function that overloads the "+" operator works fine but my friend function that overloads the "-" operator seems to have trouble finding data that the member function is able to use. </p>
  
  <p><strong>class def:</strong></p>
  
  <pre><code>class matrix
  {
      friend ostream&amp; operator &lt;&lt; (ostream&amp;, const matrix&amp;);
      friend bool operator == (const matrix &amp;, const matrix &amp;);
      friend matrix operator - (const matrix &amp;, const matrix &amp;);
  
  private:
      int size;
      int range;
      int array[10][10];
  
  public:
      matrix(int);
      matrix(int, int);
      bool operator != (const matrix &amp;) const;
      matrix operator + (const matrix &amp;) const;
      const matrix &amp; operator = (const matrix &amp;);
  };
  </code></pre>
  
  <p><strong>"+" overload:</strong></p>
  
  <pre><code>matrix matrix::operator + (const matrix &amp; a) const
  {
      matrix temp(size,range);
  
      for (int i = 0; i &lt; a.size; i++)
          for (int j = 0; j &lt; a.size; j++)
              temp.array[i][j] = a.array[i][j] + array[i][j];
  
      return temp;
  } 
  </code></pre>
  
  <p><strong>"-" overload:</strong></p>
  
  <pre><code>matrix operator - (const matrix &amp; a, const matrix &amp; b)
  {
      matrix temp(size, range);
  
      for (int i = 0; i &lt; a.size; i++)
          for (int j = 0; j &lt; a.size; j++)
              temp.array[i][j] = a.array[i][j] - array[i][j];
  
      return temp;
  }
  </code></pre>
  
  <p>The error I am getting in the friend function is that size, range, and array are all undeclared. I am confused because I thought member and friend functions both had equal access to data in a class and I basically doing the same thing in both functions. Does anyone know what my issue may be?</p>