shared_ptr智能指针
来源:互联网 发布:数据库流程图怎么话 编辑:程序博客网 时间:2024/05/10 18:14
#include <iostream>#include <memory>#include <string>/*shared_ptr类 智能指针也是模板*/void f(std::shared_ptr<std::string> p){std::string* plocal = p.get();//智能指针的get()函数,std::cout << *plocal << std::endl;//打印普通指针 所指的内容return;}int main(int argc, char const *argv[]){std::shared_ptr<std::string> p1(new std::string ("hello world"));//显式f(p1);std::shared_ptr<int> p2 = std::make_shared<int>(52);//最安全的分配和使用std::shared_ptr<std::string> p3 = std::make_shared<std::string>(10,'a');std::cout << "p2: " << *p2 << "p3 : " << *p3 << std::endl;auto a = std::make_shared<int>(42);std::cout << *a << std::endl;return 0;}
编译时,记得加上 -std=c++11选项!
-----------------
知识无价!
0 0
- C++ 智能指针 shared_ptr
- 智能指针 shared_ptr
- Boost智能指针:shared_ptr
- 智能指针shared_ptr
- 智能指针shared_ptr
- 智能指针shared_ptr
- 智能指针shared_ptr
- 智能指针 shared_ptr
- 智能指针之shared_ptr
- 智能指针 shared_ptr
- 智能指针--shared_ptr&&weak_ptr
- 智能指针之 shared_ptr
- 智能指针shared_ptr
- 智能指针boost::shared_ptr
- 智能指针boost::shared_ptr
- 智能指针 shared_ptr 解析
- C++智能指针--shared_ptr
- Boost智能指针:shared_ptr
- 几款消息中间的调研
- File类概述
- ueditor 上传图片 无法获取到数据 jsp struts2+spring
- Binary Witch
- 第四天:用数组方式写一个扑克牌案例(创建,洗牌,发牌)
- shared_ptr智能指针
- 操作系统大纲
- 做一个简单的井字棋(一)
- Linux C语言编程day-2
- Python和numpy下载安装方法
- 如何测试大端存储和小端存储
- 文章标题
- C\C++ 变量生存周期
- 文章标题