user3215228
user3215228

Reputation: 313

stream insertion operator cascade reference to object

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

Answers (1)

Lightness Races in Orbit
Lightness Races in Orbit

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

Related Questions