Bja*_*une 8 c++ placement-new move-semantics c++11 move-assignment-operator
这是使用移动构造函数为大多数类定义移动赋值的一种非常简单的方法:
class Foo {
public:
Foo(Foo&& foo); // you still have to write this one
Foo& operator=(Foo&& foo) {
if (this != &foo) { // avoid destructing the only copy
this->~Foo(); // call your own destructor
new (this) Foo(std::move(foo)); // call move constructor via placement new
}
return *this;
}
// ...
};
Run Code Online (Sandbox Code Playgroud)
这个调用你自己的析构函数的序列是否跟随在标准C++ 11中的this指针安全位置新增?