is it possible to simply serialize C++ objects

前端 未结 4 822
伪装坚强ぢ
伪装坚强ぢ 2020-12-22 05:03

Can you cast an object to a string of hex data (similar to how packets are sent) and then store that and then cast the object back? I know its possible with C structs which

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-22 05:17

    If all you are interested in doing is serializing objects in C++ to either binary blobs of data, or to JSON, or to XML, you can take a look at a serialization library such as cereal or Boost serialization.

    If you need support for raw pointers or references, Boost is the way to go. If you don't need to serialize raw pointers to things, and instead either use C++11 style smart pointers or no pointers at all, I'd recommend using cereal, as it supports pretty much everything in the standard library, whereas Boost has a more limited subset.

提交回复
热议问题