I found the answer for both C Structs and C# classes but came back empty-handed concerning C++. EDIT : In C, you can't. In C# it's the GetProperties() method.
The context: I have a C++ class with public attributes (let's say a Point with X, Y, Z). I want to send these attributes via UDP to a Java client. My idea was to create a byte (char *) buffer with the three attributes (i took care of the endianness problems).
prepareForUdp(char * buffer)
{
int offset = 0;
int offsetValue = 4;
char tempBuffer[16];
memcpy( tempBuffer, &X_, sizeof(X_) );
offset = offset + offsetValue;
memcpy( tempBuffer + offset, &Y_, sizeof(Y_) );
offset = offset + offsetValue;
memcpy( tempBuffer + offset, &Z_, sizeof(Z_) );
offset = offset + offsetValue;
memcpy( buffer, tempBuffer, sizeof(buffer) );
}
I want my interface to be evolutive, because the point may get a fourth, a five, or an n-th dimension, and I want my prepareForUdp() method to be (relatively) generic.
My question is : how do I loop (or iterate) through my attributes ?