title: How to overload operator in C++ when overloaded << and arithmetic operator are used continuously?
body: <pre class="lang-cpp prettyprint-override"><code>class Fraction {
  public:
      int a, b;
  
      static int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
  
      Fraction() {}
  
      Fraction(int _a, int _b) : a(_a), b(_b) {
          // processing...
      }
  };
  
  Fraction operator+(const Fraction &amp;x, const Fraction &amp;y) {
      // processing...
      return Fraction(ta, tb);
  }
  
  std::ostream &amp;operator&lt;&lt;(std::ostream &amp;os, Fraction &amp;f) {
      os &lt;&lt; f.a &lt;&lt; &quot;/&quot; &lt;&lt; f.b;
      return os;
  }
  
  int main() {
      Fraction f1(1, 6);
      Fraction f2(1, 4);
      Fraction f3 = f1 + f2;
      cout &lt;&lt; f3 &lt;&lt; endl; // successful
      cout &lt;&lt; f1 + f2 &lt;&lt; endl; // error
  }
  </code></pre>
  <p>As shown in the code, when I compile this code file, it shows an error in the last line</p>
  <pre><code> error: invalid operands to binary expression ('std::__1::ostream' (aka 'basic_ostream&lt;char&gt;') and 'Fraction')
      cout &lt;&lt; f1 + f2 &lt;&lt; endl;
  </code></pre>
  <p>So how to overload operators in C++ when overloaded &lt;&lt; and arithmetic operators are used continuously?</p>