given a class
struct {
int a1;
bool a2;
...
char* a500;
...
char a10000;
}
I want to print or stream out
There is no way to enumerate members of the class in C++, since there is no reflection in C++. So you cannot have access to the variable name.
You could use pointers to members though...
void PrintMemberValue(int MyClass::*p, MyClass const & obj)
{
cout << "Member has value " << obj.*p;
}
MyClass obj;
int MyClass::*p = &MyClass::a1;
PrintMemberValue(p, obj);
p = &MyClass::a2;
PrintMemberValue(p, obj);
etc