Why operator= returns reference not const reference

后端 未结 6 570
轻奢々
轻奢々 2020-12-11 05:29

The original question is related to overloading operator= and I like to share my findings as it was nontrivial for me to find them. I cannot imagine reasonable example to us

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-11 06:06

    One good reason is that one of the requirements in the standard for a class X to be useable in the standard containers is that the expression a = b must have type X& (where a is an lvalue of type X and b is an rvalue of type X).

提交回复
热议问题