Providing code hints/tags in C++ structs like in Golang

时间:2018-09-22 22:47:20

标签: c++ go reflection

In Golang I can write:

type Person struct {
    Id int `json:"id"`
}

Then on JSON.Marshal(Person{}), I get {"id": 0}. That is possible due to the json tag related to the Id field. Furthermore, I can provide any custom information in the tag section and treat it later using reflect on the struct.

Is there some analogy in C++, where I can provide additional info for a field?

1 个答案:

答案 0 :(得分:3)

不。 C ++在该语言中没有任何序列化支持。您必须使用代码编写它,或者可以使用第三方工具和库,例如Cereal,Boost.Serialization,FlatBuffers,ThorSerializer,Cap'n Proto等。