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

}

相关推荐
whoarethenext1 小时前
初始https附带c/c++源码使用curl库调用
服务器·c++·qt·https·curl
cloues break.2 小时前
C++进阶----多态
开发语言·c++
Despacito0o2 小时前
C++核心编程:类与对象全面解析
开发语言·c++
CodeWithMe5 小时前
【C++】线程池
开发语言·c++
wuqingshun3141596 小时前
蓝桥杯 2. 确定字符串是否是另一个的排列
数据结构·c++·算法·职场和发展·蓝桥杯
hu_yuchen6 小时前
C++:BST、AVL、红黑树
开发语言·c++
炯哈哈6 小时前
【上位机——MFC】视图
开发语言·c++·mfc·上位机
我也不曾来过16 小时前
继承(c++版 非常详细版)
开发语言·c++
1白天的黑夜17 小时前
贪心算法-2208.将数组和减半的最小操作数-力扣(LeetCode)
c++·算法·leetcode·贪心算法
AAAA劝导tx8 小时前
List--链表
数据结构·c++·笔记·链表·list