奇怪,为什么可以运行

#include<memory>
#include<iostream>
#include<utility>
#include<string.h>
#include<stdlib.h>
using namespace std;
class Widget{
public:
Widget(){ cout << "Widget constructor called" << endl; }
~Widget(){ cout << "~Widget called" << endl; }
Widget& operator=(const Widget&) { cout << "Widget operator= called" << endl; };
Widget(Widget& a){
cout << &a << endl;
cout << "Widget non-const copy constructor called" << endl;
}

/*Widget(Widget&& a){
cout << &a << endl;
cout << "Widget move constructor called"<<endl;
}*/

};

int main()
{
Widget a;
cout << &a << endl;
Widget();
Widget c(move(a));
//cout << &b << endl;
cout << atoi("130=") << endl;
return 0;
}

这里我将 move(a)作为实参传给了Widget的复制构造函数,但复制构造函数的形参我故意弄成了非const的形式,为什么这样也能接收成功呢?

猜你喜欢

转载自www.cnblogs.com/cool-breezer/p/10568024.html