问题
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