任何人都可以向我解释为什么以下程序产生输出"cpy:0"(至少在使用g ++ 4.5.2编译时):
#include<iostream>
struct A {
bool cpy;
A() : cpy (false) {
}
A (const A & a) : cpy (true) {
}
A (A && a) : cpy (true) {
};
};
A returnA () { return A (); }
int main() {
A a ( returnA () );
std::cerr << "cpy: " << a.cpy << "\n";
}
Run Code Online (Sandbox Code Playgroud)
当我试图弄清楚这个例子看似奇怪的结果时出现了问题:使用常量数据成员或引用成员移动类的ctor