title: Can ostream overloading be a function member?
body: <p>I have a class <code>Counter</code> and I want to overload <code>operator &lt;&lt;</code> to output the data member of <code>Counter</code>. I tried to make the ostream overloading a member function:</p>
  
  <pre><code>Counter{
  public:
      std::ostream&amp; operator&lt;&lt;(std::ostream&amp; outStream, const Counter&amp; c);
  private:
      int count_;
  };
  
  std::ostream&amp; Counter::operator&lt;&lt;(std::ostream&amp; outStream, const Counter&amp; c){
      outStream &lt;&lt; c.count_;
      return outStream;
  }
  </code></pre>
  
  <p>But the g++ compiler always outputs the same error:</p>
  
  <blockquote>
    <p><code>‘std::ostream&amp; Counter::operator&lt;&lt;(std::ostream&amp;, const Counter&amp;)’</code> must take exactly one argument</p>
  </blockquote>
  
  <p>However, if I changed the overloading function to be a friend of the class, it worked all well, like this:</p>
  
  <pre><code>Counter{
  public:
      friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp; outStream, const Counter&amp; c);
  private:
      int count_;
  };
  
  std::ostream&amp; operator&lt;&lt;(std::ostream&amp; outStream, const Counter&amp; c){
      outStream &lt;&lt; c.count_;
      return outStream;
  }
  </code></pre>
  
  <p>Does this mean that the the stream operator overloading cannot be a member function of a class?</p>