Is it possible to serialize and deserialize a class in C++?

前端 未结 13 2882
我寻月下人不归
我寻月下人不归 2020-11-22 02:18

Is it possible to serialize and deserialize a class in C++?

I\'ve been using Java for 3 years now, and serialization / deserialization is fairly trivial in that lang

13条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 02:52

    Boost is a good suggestion. But if you would like to roll your own, it's not so hard.

    Basically you just need a way to build up a graph of objects and then output them to some structured storage format (JSON, XML, YAML, whatever). Building up the graph is as simple as utilizing a marking recursive decent object algorithm and then outputting all the marked objects.

    I wrote an article describing a rudimentary (but still powerful) serialization system. You may find it interesting: Using SQLite as an On-disk File Format, Part 2.

提交回复
热议问题