我有一個結構(可以是類),它在「H」文件中定義:運行時類型和屬性識別在C++中
struct my_struct {
char * a;
char * b;
char * other_char;
char * hello;
// other 100 chars
// new chars can be added in future
};
我用這個結構在我的項目。所以,我得到這個結構和通話功能的每一個屬性和值:
void foo(char* attribute_name, char* attribute_value) {...}
有什麼辦法來動態獲取結構的屬性名稱和值?
我需要它,因爲結構不斷提高,我需要添加代碼,並重新編譯該項目。
我需要的是這樣的:
void foo(my_struct s) {
int attributes = s.getAttrSize();
for (int i=0; i<attributes; ++i){
char* attribute_name = s.getAttrName[i];
char* attribute_value = s.getAttriValue[i];
}
}
的感謝!
爲什麼使用multimap而不是map? – Shuo 2011-03-11 14:11:18