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 释放指针?
- 如何对自定义类的向量使用std::find()? 2022-11-07
- Stroustrup 的 Simple_window.h 2022-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 近似搜索的工作原理 2021-01-01
- 从python回调到c++的选项 2022-11-16
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- C++ 协变模板 2021-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- 静态初始化顺序失败 2022-01-01