#include <bits/stdc++.h>
using namespace std;
//智能指针
int main(){
//unique_ptr,保证同一时间内只有一个智能指针可以指向该对象
unique_ptr<string> p3(new string("auto"));
unique_ptr<string> p4;
// p4 = p3; 不允许,会产生相应的报错
unique_ptr<string> pu1(new string ("hello world"));
unique_ptr<string> pu2;
// pu2 = pu1;会产生报错,因为留下了悬挂的unique_ptr(pu1)
unique_ptr<string> pu3;
pu3 = unique_ptr<string> (new string ("You"));
// =号的左侧是个临时变量,让权给pu3后,便被自动销毁,编译器允许这样赋值
unique_ptr<string> t1,t2;
t1 = unique_ptr<string> (new string ("You"));
t2 = move(t1);//借助move函数实现安全赋值
cout<<*t2<<endl;
return 0;
}