3
我已經用vs2011編譯了這段代碼。它首先打印構造函數然後複製構造函數。 但是,如果我更改函數返回a而不是ap,它將移動該對象。這是一個錯誤還是爲什麼它的行爲如此? * ap不是右值嗎?按值返回指針不會移動對象
struct A
{
A() { cout << "constructor" << endl;}
A(const A&) { cout << "copy constructor " << endl;}
void operator=(const A&) { cout << "assignment operator" << endl; }
A(A&&) { cout << "move copy constructor" << endl;}
void operator=(A&&) { cout << "move assignment operator" << endl;}
};
A func() { A a; A *ap = &a; return *ap; }
int main()
{
A a = func();
return 0;
}
安** xvalue ** !?突然間,我感到非常失去聯繫。感謝您的鏈接。 – NPE