Enumerate members of a structure?

前端 未结 6 889
渐次进展
渐次进展 2021-01-13 10:02

Is there a way to enumerate the members of a structure (struct | class) in C++ or C? I need to get the member name, type, and value. I\'ve used the following sample code b

6条回答
  •  礼貌的吻别
    2021-01-13 10:19

    You can specify your types in an intermediate file and generate C++ code from that, something like COM classes can be generated from idl files. The generated code provides reflection capabilities for those types.

    I've done something similar two different ways for different projects:

    • a custom file parsed by a Ruby script to do the generation
    • define the types as C# types, use C#'s reflection to get all the information and generate C++ from this (sounds convoluted, but works surprisingly well, and writing the type definitions is quite similar to writing C++ definitions)

提交回复
热议问题