0

If you don't have access to the source code of a struct or class, is there a way to know the members of that struct or class? Specifically, i want to know the names, order, and data types of the members.

hermit.crab
  • 592
  • 1
  • 5
  • 13
  • 1
    No, that's not possible. The names are part of the source code only, so if you have no source code, there are no names. – Kerrek SB May 03 '17 at 14:53
  • *If* the binary is compiled with debug symbols then you can extract some information and names from there and demangle them. – Jesper Juhl May 03 '17 at 15:16

1 Answers1

1

No. The language feature that you describe is called reflection. C++ has no support for reflection.

It is of course possible to maintain the information about classes and members and such in an external structure. Using a preprocessor, it is possible to build a system that allows defining a class and its reflection metadata without repetition.


There are proposals to add (static) reflection to the language: N4428, 4447, N4451, SG 7 Hopefully reflection will become part of C++ in the future.

eerorika
  • 181,943
  • 10
  • 144
  • 256