title: Why friend function is preferred to member function for operator<<
body: <p>When you are going to print an object, a friend operator&lt;&lt; is used. Can we use member function for operator&lt;&lt; ? </p>
  
  <pre><code>class A {
  
  public:
  void operator&lt;&lt;(ostream&amp; i) { i&lt;&lt;"Member function";}
  friend ostream&amp; operator&lt;&lt;(ostream&amp; i, A&amp; a) { i&lt;&lt;"operator&lt;&lt;"; return i;}
  };
  
  
  int main () {
  
     A a;
     A b;
     A c;
     cout&lt;&lt;a&lt;&lt;b&lt;&lt;c&lt;&lt;endl;
     a&lt;&lt;cout;
    return 0;
  }
  </code></pre>
  
  <p>One point is that friend function enable us to use it like this </p>
  
  <pre><code>cout&lt;&lt;a&lt;&lt;b&lt;&lt;c
  </code></pre>
  
  <p>What other reasons?</p>