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