I want to print an object of a user-defined type, for example cout << ob1; so I want to overload the operator <<and I want to return by value not by reference, but it gives me an error: in two files named: iosfwd and ios_base.h
ostream operator<<( ostream& out, cat& rhs){ out << rhs.a << ", " << rhs.b << endl; return out ; }
1) Is it because it cannot create a new ostream object, so should it return by reference?
but when I return the link as follows:
ostream& operator<<( ostream& out, cat& rhs){ out << rhs.a << ", " << rhs.b << endl; return out ; }
It works great.
2) any explanation?
source share