有人可以解释为什么B不编译,但C呢?我不明白为什么std :: move是必需的,因为变量已经是右值ref。rvalue refs和std :: move
struct A {
int x;
A(int x=0) : x(x) {}
A(A&& a) : x(a.x) { a.x = 0; }
};
struct B : public A {
B() {}
B(B&& b) : A(b) {} // compile error with g++-4.7
};
struct C : public A {
C() {}
C(C&& c) : A(std::move(c)) {} // ok, but why?
};
接受一个答案! – Walter 2012-11-30 14:25:30