is it possible to simply serialize C++ objects

前端 未结 4 821
伪装坚强ぢ
伪装坚强ぢ 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:19

    No. Reasons:
    a) Dynamic allocated memory, ie. pointer in the struct/class.
    b) Endianess, int-size, padding etc. of the struct, order of the members...

    Other things:
    "If" it would be possible, there is no reason to create a full object
    with constructor call before overwriting it.
    And in my opinion, you´re overusing auto.

提交回复
热议问题