提升序列化 - 序列化 std::tr1::shared_ptr?

发布于 2024-09-30 10:22:27 字数 221 浏览 3 评论 0原文

Boost::Serialization 内置了对 boost::shared_ptr 的支持。

有没有办法也对 std::tr1::shared_ptr 使用此支持?
是否可以从 std::tr1::shared_ptr<> 转换为 boost::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<>?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

末が日狂欢 2024-10-07 10:22:27

由于实现不同,无法进行铸造。另外,使用从另一个shared_ptr类型上的get()返回的值创建一个shared_ptr类型的实例将无法正常工作,因为引用计数将在代码中的不同点变为0,这会导致在最后一个之前删除对象使用它。
我不是 boost::serialization 的专家,但作为 std::tr1::shared_ptr<> 的接口和 boost::shared_ptr>>几乎相同,您很可能只需克隆 boost::shared_ptr<> 的序列化/反序列化代码即可只需要替换shared_ptr的命名空间即可。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文