return value of operator overloading in C++

前端 未结 5 2100
逝去的感伤
逝去的感伤 2020-11-29 18:19

I have a question about the return value of operator overloading in C++. Generally, I found two cases, one is return-by-value, and one is return-by-reference. So what\'s the

5条回答
  •  天命终不由人
    2020-11-29 18:30

    Depending on the operator you may have to return by value.

    When both can be used though, like in operator+= you could consider the following:

    • If your objects are immutable it's probably better to return by value.
    • If your objects are mutable it's probably better to return by reference.

提交回复
热议问题