本文介绍了提高序列化和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

这篇关于提高序列化和std :: shared_ptr的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 09:33