0

I am new to C++. Google didn't help out. Is there any way to show all member elements of a non user-defined struct? I understand I can always return to the documentation of the struct, but it would be nice if there is a function to which I can pass any struct and get a list of all elements in that struct viewed in the console. For example, how can I know the elements in the object myTm which is of type tm (tm is a struct) in the following code:

#include <ctime>
#include <iostream>

int main()
{
tm myTm;  //tm is a struct that is included by <ctime>
return 0;
}
BENS
  • 177
  • 1
  • 6
john2000
  • 3
  • 1
  • Normally you use a software development tool called IDE (Integrated Development Environment) to show you this information – M.M Jan 21 '17 at 10:36
  • You would use an IDE for that. Typically Right click->Show definition. – Bo Persson Jan 21 '17 at 10:37
  • Works,, thanks a lot – john2000 Jan 21 '17 at 10:46
  • Perhaps you're looking for reflection (in that case, check out the CppCon 2016 talk on reflections for POD types)... – lorro Jan 21 '17 at 10:51
  • You are probably just looking for an IDE feature, but if you want this capability at runtime, then you are out of luck. See http://stackoverflow.com/questions/41453/how-can-i-add-reflection-to-a-c-application – Christian Hackl Jan 21 '17 at 11:19

2 Answers2

0

If you are using Windows you could use Visual studio IDE , it's nice ,free and it will help you getting all of that.all you have to do is Click Right and go to definition of that struct .

BENS
  • 177
  • 1
  • 6
0

Usually there is such a function in IDE's. Right-click the #include and there might be an option to see the declaration. As far as I know, there is no C++ function that solves the problem

Petr
  • 239
  • 4
  • 16