c++ - 使 shared_ptr 不使用删除

标签 c++ boost

在我的代码中,我希望 boost::shared_ptr 不调用 delete,而是调用 ptr->deleteMe()。

我还有一些返回 ptr 的 C 风格函数。我可以叫它 lib_freeXYZ(ptr);而不是尝试删除?

最佳答案

或者如何使用 STL 来提供包装仿函数 - Doug T. 描述但没有自定义调用者。

boost::shared_ptr<T> ptr( new T, std::mem_fun_ref(&T::deleteMe) );
boost::shared_ptr<S> ptr( new S, std::ptr_fun(lib_freeXYZ) );

关于c++ - 使 shared_ptr 不使用删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/441306/

相关文章:

c++ - 为什么 Gun *gun=&machinegun 有效,而 *gun=&machinegun 无效?

c++ - 如何从被阻止的调用中返回?

java - android ndk wrapped c++ file 获取android系统文件路径

c++ - boost 图 : How to copy the nodes and edges of a graph without copying properties?

c++ - 将引用传递给Boost Bind Class C++

c++ - boost::asio 是否使用 ssl session 缓存?

c++ - 与数组一起使用时的双指针差异

c++ - Producer Consumer 使用 intel-pin 内线程

c++ - boost read_wkt 产生了无效的多边形

c++ - auto_ptr 和 dynamic_pointer_cast