BAE HA RAM
BAE HA RAM

Reputation: 615

Why does operator<< of istream class have return/parameter type of reference in C++?

I'm studying the overloading of operator<< and operator>>.

So I must use istream/ostream class to override.

But I don't understand why overridden operators take istream/ostream object by reference and return a reference.

Can you explain this?

Upvotes: 0

Views: 120

Answers (1)

SoronelHaetir
SoronelHaetir

Reputation: 15172

It is done because stream types are not copyable and so that you can stack operations. std::cin >> num1 >> num2; and the like.

Upvotes: 1

Related Questions