Boost Serialization - Serialize std::tr1::shared_ptr?

核能气质少年 提交于 2019-12-24 03:06:04

问题


Boost::Serialization has builtin support for boost::shared_ptr<>.

Is there a way to use this support for std::tr1::shared_ptr<> too?
Is it possible to cast from std::tr1::shared_ptr<> to boost::shared_ptr<>?


回答1:


A casting will not be possible as implementations differ. Also creating an instance of the one shared_ptr type with the value returned from get() on the other shared_ptr type will not work correctly as the reference countings will go to 0 at different points in your code which leads to deletion of the object before the last use of it. I am not an expert of boost::serialization but as the interfaces of std::tr1::shared_ptr<> and boost::shared_ptr<> are nearly identical it is very likely that you can just clone the serialization/deserialization code of boost::shared_ptr<> and only have to replace the namespace of the shared_ptr.



来源:https://stackoverflow.com/questions/4094604/boost-serialization-serialize-stdtr1shared-ptr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!