【发布时间】:2013-01-24 21:30:17
【问题描述】:
我有一个类似以下的对象,我正在尝试实现一个移动构造函数,以便您可以插入std::vector<Mesh>。
struct Mesh
{
std::vector<Vector3> vPoint;
bool Valid;
Mesh(Mesh&& other)
{
vPoint = std::move(other.vPoint);
Valid = std::move(other.Valid);
}
};
这是正确的方法吗? 如果是这样,在 std::move 对其进行操作后 other.Valid 的值是多少?
编辑:
另外,如果我有这个对象的一个实例,我是否需要在以下场景中使用 std::move?
std::vector<Mesh> DoSomething()
{
Mesh mesh; //Imagine vPoint is filled here to
std::vector<Mesh> meshes;
meshes.push_back(std::move(mesh)); // Here is my question, std::move? or just pass mesh here?
return meshes;
}
【问题讨论】:
-
为什么要
movebool? -
@us2012 我只是好奇
std::move<bool>或其他整数类型会发生什么。是否将值复制到this.Valid,然后将other.Valid设置为bool 的默认值(又名false)?
标签: c++ c++11 move-semantics