operator overloading using ostream and chaining. Why return by reference?

后端 未结 5 1169
粉色の甜心
粉色の甜心 2021-02-10 19:24

There are many questions and answers for this, but I can\'t really find why we need to return by reference.

If we have (assume operator is already correctly ov

5条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-10 19:51

    Returning by value does not prevent chaining. But if you return by value, you're returning a copy, which is generally not what you want in this case.

提交回复
热议问题