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

前端 未结 13 2895
我寻月下人不归
我寻月下人不归 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:36

    As far as "built-in" libraries go, the << and >> have been reserved specifically for serialization.

    You should override << to output your object to some serialization context (usually an iostream) and >> to read data back from that context. Each object is responsible for outputting its aggregated child objects.

    This method works fine so long as your object graph contains no cycles.

    If it does, then you will have to use a library to deal with those cycles.

提交回复
热议问题