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 小时前
007-nlohmann/json 项目应用-C++开源库108杰
c++·开源·json·nlohmann·现代c++·d2school·108杰
菠萝014 小时前
共识算法Raft系列(1)——什么是Raft?
c++·后端·算法·区块链·共识算法
海棠蚀omo4 小时前
C++笔记-C++11(一)
开发语言·c++·笔记
凌佚5 小时前
rknn优化教程(一)
c++·目标检测·性能优化
Lenyiin7 小时前
《 C++ 点滴漫谈: 四十 》文本的艺术:C++ 正则表达式的高效应用之道
c++·正则表达式·lenyiin
yxc_inspire9 小时前
基于Qt的app开发第十三天
c++·qt·app·tcp·面向对象
虾球xz9 小时前
CppCon 2015 学习:Concurrency TS Editor’s Report
开发语言·c++·学习
潇-xiao9 小时前
Qt 按钮类控件(Push Button 与 Radio Button)(1)
c++·qt
板鸭〈小号〉10 小时前
命名管道实现本地通信
开发语言·c++
YKPG11 小时前
C++学习-入门到精通【14】标准库算法
c++·学习·算法