Can I enumerate char*
members of a class (or struct) in C++? If so can I print the variables names as strings? Using pre-processor?
I have a class with all const char* members. It would be good if there was an elegant way to enumerate each member variable and check name as a string against a string key I am given.
Here is the sort of code which could be used?
Can anyone think of a way to do this?
class configitems {
public:
configitems() : host(0), colour(0) {}
const char* host;
const char* colour;
//... etc
};
int main() {
configitems cfg;
//cfg.colour = "red";
//receive an config item as a string. I want to check that the item is a valid one (eg is a
//variable of class configitem) and then populate it.
//eg get colour=red so want to do something like this:
if(isConfigItem("colour")) {
cfg.<colour> = "red";
}
return 0;
}