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

}

相关推荐
万法若空3 小时前
C++ <memory> 库全方位详解
开发语言·c++
代码中介商3 小时前
C++ 类型转换深度解析:static_cast、dynamic_cast、const_cast、reinterpret_cast
开发语言·c++
青小莫3 小时前
C++之string(OJ练习)
开发语言·c++·stl
6Hzlia4 小时前
【Hot 100 刷题计划】 LeetCode 199. 二叉树的右视图 | C++ DFS 逆序遍历
c++·leetcode·深度优先
-Marks-4 小时前
【C++编程】STL简介 --- (是什么 | 版本发展历程 | 六大组件 | 重要性缺陷以及如何学习)
开发语言·c++·学习·stl·stl版本
CoderCodingNo5 小时前
【信奥业余科普】C++ 的奇妙之旅 | 12:程序的交互与加工——数据的输入与算术运算
开发语言·c++
yx868xy5 小时前
Cuda加速直线拟合
c++·cuda
蜗牛在听雨5 小时前
基于 C++ 的 UG/NX 二次开发环境配置
c++·二次开发·ug
SimpleLearingAI6 小时前
C++虚函数详解
开发语言·c++