问题描述
我发现这两个C的结构和C#类的答案,但回来两手空空关于C ++。
编辑:在C中,你不能。
在C#中它的的GetProperties()方法。
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.
上下文:我有公共属性的C ++类(比方说使用X的一个点,Y,Z)。我想通过UDP这些属性发送到Java客户端。我的想法是创建一个字节(字符*)与三个属性缓冲(我照顾的字节顺序问题)。
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) );
}
我希望我的界面是进化的,因为点可能拿到了第四,五,或第N维的,我希望我的prepareForUdp()方法是(相对)通用。
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 ?
推荐答案
有没有反映在C ++中。因此,答案是,你不能:)
There is no reflection in C++. So, the answer is, you can't :)
这篇关于我可以通过一个C ++类的(公共)属性循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!