出於某種原因,下面的代碼永遠不會調用Event::Event(Event&& e)
這個C++ 0x代碼爲什麼不調用移動構造函數?
Event a;
Event b;
Event temp;
temp = move(a);
a = move(b);
b = move(temp);
爲什麼不呢?使用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;
};
謝謝! (標記爲答案是因爲你的第一個答案) – 2009-06-29 18:25:06