Are move semantics incomplete?

前端 未结 3 1130
暗喜
暗喜 2021-01-02 06:59

Move semantics replace copy semantics in situations where copying is inefficient. Copy semantics deals fully with copyable objects, including const objects.

Already,

3条回答
  •  甜味超标
    2021-01-02 07:52

    So basically you're saying it should be possible to move a const object into another const object and destroy the original?

    Sorry but I think the whole point of making it const is to prevent this.

    Otherwise it would form a loophole: you could destroy-move a const object out of its memory location, then you destroy-move another const object into the memory location of the first one (via placement new).

    Now the object has changed even though it was const... so essentially const was useless.

    See comments below...

提交回复
热议问题