问题描述
是否有升压股票无操作释放器与使用的boost :: shared_ptr的
的静态对象,等等。
Is there a stock no-op deallocator in Boost to use with boost::shared_ptr
for static objects, etc.
我知道这是超小事来写,但我不希望我的洒code额外的小功能,如果已经有一个可用的。
I know it's ultra-trivial to write, but I don't want to sprinkle my code with extra tiny functions if there is already one available.
推荐答案
是的,有一个在这里:
#include <boost/serialization/shared_ptr.hpp> // for null_deleter
class Foo
{
int x;
};
Foo foo;
boost::shared_ptr< Foo > sharedfoo( &foo, boost::serialization::null_deleter() );
有,当然,与你需要知道你叫不存储供以后使用的shared_ptr的功能,因为它实际上违背的shared_ptr,该政策的事实的危险底层对象仍然有效,直到该shared_ptr的最后isntance的。
There is, of course, a danger with the fact that you need to know the function you call doesn't store the shared_ptr for later use, as it actually goes against the policy of shared_ptr in that the underlying object remains valid until that of the last isntance of the shared_ptr.
这篇关于无操作释放器升压:: shared_ptr的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!