C++11 std::shared_ptr + boost::serialization [英] c++11 std::shared_ptr + boost::serialization

查看:106
本文介绍了C++11 std::shared_ptr + boost::serialization的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人已经设法使用 boost::serialization 序列化 C++11 std::shared_ptr.有很多过时的帖子,但没有一个可以接受的解决方案.我不打算讨论为什么我要使用 std::shared_ptr 接受它!

Hi has anybody already managed to serialize a C++11 std::shared_ptr with boost::serialization. There are lots of obsolete posts out there but none with an acceptable solution. I am not going into discussion why I want to use the std::shared_ptr just accept it!

我发现了另一个帖子:boost serialize 和 std::shared_ptr 但它没有回答我的问题如何序列化 std::shared_ptr 它只建议使用 boost::shared_ptr 这在我的情况下是不可能的.

I found this other post: boost serialize and std::shared_ptr but it does not answer my problem how to serialize the std::shared_ptr it only suggests to uses the boost::shared_ptr which is not possible in my case.

这篇文章如何提升::序列化与 C++11 中的 std::shared_ptr 一起使用吗? 也只推荐使用 boost::shared_ptr.

And this post How can boost::serialization be used with std::shared_ptr from C++11? does also only recommend to use boost::shared_ptr.

如果有人已经找到了设法序列化 std::shared_ptr 的工作,我会很感兴趣.

I would be interested if anybody has already found a work around that manages to serialize the std::shared_ptr.

我终于找到了解决我的问题的方法,参见 https://stackoverflow.com/a/14999396/2039157我的回答.

I finally found a solution to my problem see https://stackoverflow.com/a/14999396/2039157 for my answer.

推荐答案

难道不能仅仅"创建一个序列化程序<<<和 deserializer>> 将只是"将 shptr 序列化转换为对象指针序列化?如果还没有完成,我几乎可以肯定这在 < 中是可能的.100 行代码.

Isn't it possible to "just" create a serializer<< and deserializer>> that will "just" turn the shptr-serialization into object-pointer serialization? If not done yet, I'm almost sure that this is possible in < 100 lines of code.

另外,我知道您已经指定不要询问,但我仍然会:当您尝试序列化 shptr 的X"变量时,为什么不能序列化取消引用的 *shptr ?这似乎不足以让我费心为 smartptrs 添加序列化.. 嗯.. 好的.美学.但我仍然认为这是可行的.

Also, I know that you have specified not to ask, but still I will: When you try to serialize "X" variable that is shptr, why can't you just serialize dereferenced *shptr ? That doesn't seem enough difference for me to bother with adding serialization for smartptrs.. Hm.. ok. esthetics. But still I think it is doable.

无论如何,但是您可能会遇到另一堵墙:如果您使用类继承并且如果您在 shptr 中通过指向基类的指针携带对象,那么您将遇到一个明显的问题,即序列化程序将不知道它实际上是被命令序列化的.但这是一个没有 RTTI 的序列化的经典问题,好吧,你必须以某种方式解决,但这不是 shptrs 的问题.

Anyways, however you can hit another wall: if you use class inheritance and if you carry along the objects within shptr via pointer to the base class, you will have the obvious problem that the serializer will not know what actually it is ordered to serialize. But that's a classic problem for serialization without RTTI, that, well, you hve to somehow solve, but that's not the problem of shptrs.

免责声明:我上次使用 boost::serialization 是几年前.我实际上并没有尝试序列化 shptr,但据我所知,这是一个相当开放的框架,相对容易扩展任何自定义类型,所以我认为 shptr 并不比我管理的奇怪类更好-序列化:)

disclaimer: the last time I used boost::serialization was few years ago. I did not actually try to serialize shptr, but from what I remember, that was quite an open framework, relatively easy to extend for any custom type, so I assume shptrs are no better than my weird-classes-that-I-managed-to-serialize :)

这篇关于C++11 std::shared_ptr + boost::serialization的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆