由于某种原因,以下代码永远不会调用Event::Event(Event&& e)
Event a;
Event b;
Event temp;
temp = move(a);
a = move(b);
b = move(temp);
why not?
Using std::swap
调用一次。
class Event {
public:
Event(): myTime(0.0), myNode(NULL) {}
Event(fpreal t, Node* n);
Event(Event&& other);
Event(Event const& other) = delete;
~Event();
bool operator<(Event const& other) const { return myTime < other.myTime; }
bool operator>(Event const& other) const { return myTime > other.myTime; }
fpreal getTime() const { return myTime; }
void setTime(fpreal time) { myTime = time; }
Node* getNode() const { return myNode; }
private:
fpreal myTime;
Node* myNode;
};
您没有使用移动构造函数。我认为交换是这样实现的
Event a;
Event b;
Event temp(move(a)); // this one wants to use a move constructor
a = move(b);
b = move(temp);
您想要使用移动赋值运算符,但该运算符在代码中不存在,因此它会退回到复制赋值运算符。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)