Why operator= returns reference not const reference

后端 未结 6 575
轻奢々
轻奢々 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:00

    Why should it be const? If you're assigning to it, obviously it's modifiable. That would be artifically limiting.

    As for use cases, why not:

    T &local = t1 = t2 = t3;
    

    In this example, local isn't const.

提交回复
热议问题