提高序列化和std :: shared_ptr的

问题描述:

我有一个对象,以下字段:

I Have a object which the following field :

boost::unordered_map<std::string, std::shared_ptr<Foo> > m_liste_;

我想序列化,但它似乎的std :: shared_ptr的不能以简单的方式进行序列化

I would like to serialize it, but it seems std::shared_ptr can't be serialized in a simple manner

任何人有一个解决方案?

anyone have a solution ?

我怀疑你是缺少一个包括

I suspect you are missing an include,

#include <boost/serialization/shared_ptr.hpp>

链路,在底部

此外,例如使它看起来像叠和周期是默认的照顾。

Also, the example makes it look like aliasing and cycles are taken care of by default.

_Of当然,其周期会导致与shared_ptr的什么都没有做系列化潜在的内存泄漏,你还是得听从那些(避免周期或合理使用的weak_ptr的)_

_Of course, having cycles will lead to potential memory leaks with shared_ptr that have nothing to do with serialization, and you'll still have to heed those (by avoiding cycles or judicious use of weak_ptr)_

另请参阅:

  • Template serialization - shared_ptr
  • shared_ptrRevisited