Because std::unique_ptr is designed with move semantics in mind, copy initialization and copy assignment are disabled. If you want to transfer the contents managed by std::unique_ptr, you must use move semantics.
std::unique_ptr
可以使用 copy 初始化吗?
Because std::unique_ptr is designed with move semantics in mind, copy initialization and copy assignment are disabled. If you want to transfer the contents managed by std::unique_ptr, you must use move semantics.
std::unique_ptr
可以使用 copy 初始化吗?
std::move can be used whenever we want to treat an l-value like an r-value for the purpose of invoking move semantics instead of copy semantics.
std::move
在什么情况下可以使用?
Move semantics means the class will transfer ownership of the object rather than making a copy.
move semantics 是什么意思?