How to get all class properties / variables at runtime / dynamically in C ++

Is it possible to get all the variables and methods of a class at runtime? if so, how? I did this in C # using Reflection. but now I am working in C ++.

+4
source share
4 answers

In C ++, there is no way to do what you ask. As suggested in another answer, RTTI may help you, but probably this is not what you need.

If you describe in more detail what you are trying to do and why you need reflection, we can offer other solutions in C ++.

+6
source

You can use RTTI in C ++.

This is just an opinion: it is not as simple / laid-back as the C # API.

Also check out this SO question.

+2
source

While you can determine the type of an object using RTTI, C ++ does not fully reflect, and you cannot take a regular C ++ class and determine which methods or variables it has.

+1
source

I don’t think there is a way to list class members. Some time ago, I needed the same thing, and in the end it was allowed to manually format each member and each class of interests in my own container. Even then, the members were of the same base type (replacing the Object class from C #). Enumerating members and calling the basic function of each member is easy. It works and I am happy.

0
source

All Articles