看到网上的一段测试移动构造函数的代码,如下,结果只走了默认构造函数
#include <iostream>
class A {
public:
A() {
std::cout << "default Constructor" << std::endl;
}
A(const A&) {
std::cout << "copy Constructor" << std::endl;
}
A(A &&) {
std::cout << "move Constructor" << std::endl;
}
void f() const{
std::cout << "ffff" << std::endl;
}
A & operator=(const A & a ) {
std::cout << "operator = &" << std::endl;
return *this;
}
A& operator=(A && a) {
std::cout << "operator = && " << std::endl;
return *this;
}
};
A getA() {
A a;
return a;
}
int main() {
A b = getA();
return 0;
}