unique_ptr离开了作用域 通过operator=或reset()赋值另一指针给管理的unique_ptr对象。 unique_ptr独占所有权意味着无法通过复制的方式获取unique_ptr管理的对象指针,因为复制意味着内部对象指针有两个副本,互相不知道所指对象资源是否已释放,只能通过移动的方式获取对象的所有权,具体表现为unique_ptr的复制构造函数和复制...
unique_ptr(constunique_ptr&)=delete;unique_ptr&operator=(constunique_ptr&)=delete;private:std::pair<D,pointer>_Mypair;};structPerson{Person()=default;~Person(){std::cout<<"destructor"<<std::endl;}};intmain(){autodelF=[](autoptr){deleteptr;std::cout<<"delete function"<<std::endl;}...
std::unique_ptr是一个非常简单的类。从概念上讲,基本上就是这样: