C++ 项目中的 shared_ptr

shared_ptr 允许多个指针指向同一个对象;

shared_ptr < string > p1; // shared_ptr,可以指向string

shared_ptr < list<int> > p2; // shared_ptr, 可以指向int的list

注意智能指针是指针!指针所指向的对象有一个引用次数的属性,当引用次数为0时,该对象就会被析构。

class XnetNode

{

public:

int Init(void);

std::shared_ptr<xag_nav::os::StorageBase> mp_dcStorage;

}

int XnetNode::Init(void)

{

/* 初始化数据中心 */

while (nullptr == (mp_dcStorage = Application::Instance()->createStorage()))

{

XAG_LOG_E("failed to create storage");

std::this_thread::sleep_for(1s);

}

s32Ret = mp_dcStorage->setUserData(pType, const_cast<char *>(data.c_str()), data.size());

}

相关推荐
呜喵王阿尔萨斯2 小时前
git命令解析
c++·git
Murphy_lx7 小时前
Lambda表达式
开发语言·c++
yangpipi-7 小时前
C++并发编程-23. 线程间切分任务的方法
开发语言·c++
楼田莉子8 小时前
C++算法专题学习——分治
数据结构·c++·学习·算法·leetcode·排序算法
ulias2128 小时前
各种背包问题简述
数据结构·c++·算法·动态规划
程序喵大人9 小时前
分享个C++线程池的实现源码
开发语言·c++·线程池
FL16238631299 小时前
[ubuntu][C++]onnxruntime安装cpu版本后测试代码
linux·c++·ubuntu
要做朋鱼燕9 小时前
【C++】 priority_queue 容器模拟实现解析
开发语言·c++·笔记·职场和发展
励志不掉头发的内向程序员10 小时前
C++进阶——继承 (1)
开发语言·c++·学习
mit6.82412 小时前
并查集|栈
c++