s_m
s_m

Reputation: 129

Is there a way to display/print the attribute of variable/member in C++

I am working on someone else project in C++. There are many variables which are created based on other classes. For example:

Class_C newVariable;

which Class_C is created based on Class_B and may be inherit from Class_A and so on, thus newVariable may contain many class members.

Is there anyway or easy to print or display all members of newVariable in C++?

ps. I am using Visual Studio for coding and debugging.

Upvotes: 0

Views: 196

Answers (1)

asalic
asalic

Reputation: 664

I recently asked myself the same question. Take a look at the following discussions:

how-can-i-add-reflection-to-a-c-application

generic-way-to-print-out-variable-name-in-c

Meta Classes

"Reflection" Visual Studio

To sum it up, C++ is built for speed, there is no way to get the info about your classes (during the runtime), at least not using a core feature of C++ (as we have reflection in Java). There are different tricks and extensions to do that (as you can find in the links posted above), but they are still... tricks and extensions.

Upvotes: 3

Related Questions