我花了大量的时间来摆弄Visual Studio中的complilation错误.我已经将代码提炼到下面的小编译示例中,并在IdeOne上尝试了它并得到了同样的错误,你可以在这里看到.
我想知道为什么以下代码尝试调用B(const B&)而不是B(B&&):
#include <iostream>
using namespace std;
class A {
public:
A() : data(53) { }
A(A&& dying) : data(dying.data) { dying.data = 0; }
int data;
private:
// not implemented, this is a noncopyable class
A(const A&);
A& operator=(const A&);
};
class B : public A { };
int main() {
B binst;
char* buf = new char[sizeof(B)];
B* bptr = new (buf) B(std::move(binst));
cout << bptr->data << endl;
delete[] buf; …Run Code Online (Sandbox Code Playgroud)