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

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<>?

Answer1:

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.

人吐槽 人点赞

Recommend

Comment

用户名: 密码:
验证码: 匿名发表

你可以使用这些语言

查看评论:Boost Serialization - Serialize std::tr1::shared_ptr?