正在調用d-tor內部移動賦值操作符的好習慣嗎?我可以在移動賦值運算符中調用析構函數嗎?
這裏一些示例代碼:
VectorList &operator = (VectorList &&other){
~VectorList(); // if this is not a good practice,
// I will need to paste whole d-tor here.
_buffer = std::move(other._buffer );
_dataCount = std::move(other._dataCount );
_dataSize = std::move(other._dataSize );
other._clear();
return *this;
}
我應該使用此代碼,或者我應該使用交換()與移動構造的對象?
你有沒有考慮到創建「乾淨」的對象和功能,無論是從析構函數和布展assignement操作者調用這個函數? –
非常類似於[通過destruct移動賦值+移動構造安全嗎?](http://stackoverflow.com/questions/13092240/is-move-assignment-via-destructmove-construct-safe?rq=1) –
它是通常不是*析構函數*的工作將對象返回到初始化狀態,所以我會不舒服的做到這一點。爲什麼不調用'this-> clear()'? – Galik