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());

}

相关推荐
端平入洛1 天前
auto有时不auto
c++
哇哈哈20212 天前
信号量和信号
linux·c++
多恩Stone2 天前
【C++入门扫盲1】C++ 与 Python:类型、编译器/解释器与 CPU 的关系
开发语言·c++·人工智能·python·算法·3d·aigc
蜡笔小马2 天前
21.Boost.Geometry disjoint、distance、envelope、equals、expand和for_each算法接口详解
c++·算法·boost
超级大福宝2 天前
N皇后问题:经典回溯算法的一些分析
数据结构·c++·算法·leetcode
weiabc2 天前
printf(“%lf“, ys) 和 cout << ys 输出的浮点数格式存在细微差异
数据结构·c++·算法
问好眼2 天前
《算法竞赛进阶指南》0x01 位运算-3.64位整数乘法
c++·算法·位运算·信息学奥赛
yyjtx2 天前
DHU上机打卡D31
开发语言·c++·算法
czxyvX2 天前
020-C++之unordered容器
数据结构·c++
会编程的土豆2 天前
2.25 做题
数据结构·c++·算法