I have a structure
typedef struct A
{
int a;
int b;
char * c;
}aA;
I want to iterate over each an every member of the structure
can I iterate over the members of a struct in standard c++?
No, standard c++ doesn't provide a method for accomplishing what you are asking for, you "iterate" elements of a container - you cannot iterate over members of a certain type.
"reflection" (as this type of feature is most often referred to isn't part of C++).
in c++11 you could use a std::tuple
instead of your struct A
, it will store the same kind of elements and is far easier to iterate over (using some template magic).
the elements won't have names ranging from 'a'
to 'c'
but if you'd like to print it that way this of course can be accomplished by some extra lines of code.
To access a specific element you'll use std::get
where N
is a integral ranging from 0 to std::tuple_size
(ie. 2).