做移动构造函数的正确方法是什么?
class A{
...some stuff...
private:
int i;
std::string str;
};
A::A(A &&a)
{
*this = std::move(a);
};或
A::A(A &&a)
{
this->str = std::move(a.str);
};在第二种情况下,它对std::move() int值有用吗?
发布于 2016-01-23 19:28:16
它应该是
A::A(A&& other)
: i{other.i},
str{std::move(other.str)} {
// nop
}这是移动构造函数的默认实现。
https://stackoverflow.com/questions/34967768
复制相似问题