c++11 std::shared_ptr + boost::serialization [duplicate]

半腔热情 提交于 2019-12-03 06:58:48

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.

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.

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.

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 :)

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