previous | start | next

Non-member operator<<

In a test function we could write

int main()
{
  Fraction f1(1,2);
  Fraction f2(1,4);

  cout << f1;  // Same as   operator<<(cout, f1);
  cout << endl;

  ...
}

So for

  cout << f1;  // Same as   operator<<(cout, f1);
     

cout will be passed by reference to the parameter os
f1 will be passed by constant reference to the parameter f in

 ostream& operator<<(ostream& os, const Fraction& f);
     


previous | start | next