Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

is this possible to get all the variables and methods of a class at runtime? if yes then how? I did this in C# using Reflection. but now i am working in C++.

like image 699
Asish Biswas Avatar asked Oct 25 '10 18:10

Asish Biswas


3 Answers

There is no way to do what you are asking in C++. As suggested in the other answer, RTTI can help you, but is probably not what you need.

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

like image 91
Benoit Thiery Avatar answered Nov 09 '22 22:11

Benoit Thiery


You can use RTTI in C++.

This is just an opinion: It's not as easy/straighforward as C#'s reflection API.

Also check out this SO question.

like image 21
Pablo Santa Cruz Avatar answered Nov 10 '22 00:11

Pablo Santa Cruz


While you can determine the type of an object using RTTI, C++ is not fully reflective and you cannot take a normal C++ class and determine what methods or variables it has.

like image 31
Sydius Avatar answered Nov 09 '22 22:11

Sydius