如何修改网站模板内容,久久建筑网平台,云南省公共资源交易中心,章丘网站建设一、unique_ptr类 头文件:#includememory智能指针,是一个模板。创建智能指针时,必须提供指针所指的类型与shared_ptr的不同之处: shared_ptr所指向的对象可以有多个其他shared_ptr智能指针而unique_ptr所指向的对象只能有一个unique_ptr指针,也就是自己。当unique… 一、unique_ptr类 头文件:#includememory智能指针,是一个模板。创建智能指针时,必须提供指针所指的类型 与shared_ptr的不同之处: shared_ptr所指向的对象可以有多个其他shared_ptr智能指针而unique_ptr所指向的对象只能有一个unique_ptr指针,也就是自己。当unique_ptr被销毁时,它所指向的对象也被销毁 二、unique_ptr类的初始化 unique_ptr指针需要绑定到一个new返回的指针上,并且不能直接将new的结果用赋值运算符“=”赋值给unique_ptr unique_ptrdouble p1;//正确
unique_ptrint p2(new int(42));//正确
unique_ptrint p3 = new int(42);//错误三、unique_ptr之间不存在拷贝与赋值 原因:因为unique_ptr所指向的对象只能有一个unique_ptr指针,也就是一个引用计数。因此unique_ptr不支持普通的拷贝和赋值操作 unique_ptrstring p1(new string("HelloWorld"));
unique