Reputation: 313
Why is it necessary that function below should have a reference to ostream object. I didnt properly understood it deeply and could not find it anywhere regarding stream insertion operator, function that returns reference to the object,
friend ostream& operator<<(ostream& osObject, const class& cObject)
I known about friends and all this stuff but just about this reference to object, i read related to it that this is used because we can do something like this
cout<<obj1<<obj2<<....<<....<<....
so goes on, but didnt properly understood it in detail. I would be very glad if some one would help me out. Thankyou.
Upvotes: 0
Views: 110
Reputation: 385204
The operator is a function. The function has two arguments. One is the stream to perform the streaming on, and the other is the class to stream. When you write a << b
, a operator<<
function is automatically called with arguments a
and b
.
Upvotes: 1