I want to print out an object of a user-defined type, like this cout << ob1;
so I want to overload 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 can't create a new ostream object, this is why it have to return by reference ?
but when I return by reference like this :
ostream& operator<<( ostream& out, cat& rhs){
out << rhs.a << ", " << rhs.b << endl;
return out ;
}
it works fine.
2)any explanation ?