C++智能指针unique_ptr使用示例
来源:互联网 发布:郑州编程班 编辑:程序博客网 时间:2024/06/08 19:06
unique_ptr独享一个内存,没有拷贝构造函数,也不能直接赋值,示例如下:
#include <stdarg.h>#include <stdio.h>#include <iostream>#include <vector>#include <string.h>#include <algorithm>#include <stdlib.h>#include<memory>#include <string.h>using namespace std;int main(){unique_ptr<int> p1(new int(5));//unique_ptr<int> p2 = p1; //错误,不允许直接赋值//unique_ptr<int> p3(p1); //错误,不允许拷贝构造unique_ptr<int> p4;/* 把p1的使用权交给p4 */p4.reset(p1.release());/* 将p4的使用权交给p5 */unique_ptr<int> p5(p4.release());//cout << *p4 << endl;//执行这条语句,程序会崩溃的cout << *p5 << endl;system("PAUSE");return 0;}
0 0
- C++智能指针unique_ptr使用示例
- c智能指针:unique_ptr
- 智能指针:unique_ptr使用简介
- 智能指针:unique_ptr使用简介
- 【C/C++】智能指针auto_ptr,share_ptr,unique_ptr
- 【C++】智能指针auto_ptr/unique_ptr/shared_ptr/weak_ptr!!!
- 智能指针(三):unique_ptr使用简介
- 智能指针(三):unique_ptr使用简介
- 智能指针(三):unique_ptr使用简介
- 智能指针(三):unique_ptr使用简介
- 智能指针(三):unique_ptr使用简介
- 智能指针(三):unique_ptr使用简介
- C++智能指针--unique_ptr
- c++智能指针 unique_ptr
- 智能指针unique_ptr
- C++智能指针 unique_ptr
- C++智能指针:unique_ptr
- 智能指针之unique_ptr
- 图片查看
- css禁止html标签被选中和复制
- Extjs操作Dom
- 动态规划0-1背包问题
- Lua中关于求模与求余的区别介绍
- C++智能指针unique_ptr使用示例
- Message 1070 not found; No message file for product=network, facility=TNSTNS-12546: Message 12546 no
- ksh 简单变量
- 停止monkey运行
- java动态加载指定的类或者jar包反射调用其方法
- Navicat For Oracle
- 黑马程序员——IOS学习笔记(C语言字符串和数组)
- Prestashop如何进行路由
- LeetCode题解——Reverse Linked List II