How to release pointer from boost::shared_ptr?(如何从 boost::shared_ptr 释放指针?)
问题描述
boost::shared_ptr 可以释放存储的指针而不删除它吗?
Can boost::shared_ptr release the stored pointer without deleting it?
我可以看到文档中不存在发布功能,在常见问题解答中也解释了为什么它不提供发布功能,例如不能在非唯一指针上进行发布.我的指针是独一无二的.我怎样才能释放我的指针?或者使用哪个 boost 智能指针类可以让我释放指针?我希望你不会说使用 auto_ptr :)
I can see no release function exists in the documentation, also in the FAQ is explained why it does not provide release function, something like that the release can not be done on pointers that are not unique. My pointers are unique. How can I release my pointers ? Or which boost smart pointer class to use that will allow me releasing of the pointer ? I hope that you won't say use auto_ptr :)
推荐答案
您需要使用一个删除器,您可以请求不删除底层指针.
You need to use a deleter that you can request not to delete the underlying pointer.
看到这个答案(已经标记为与此问题重复)以获取更多信息.
See this answer (which has been marked as a duplicate of this question) for more information.
这篇关于如何从 boost::shared_ptr 释放指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从 boost::shared_ptr 释放指针?
基础教程推荐
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- CString 到 char* 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
