- #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 的形式, 为什么这样也能接收成功呢?
来源: http://www.bubuko.com/infodetail-2994195.html