I am wondering if there is any way to check if a given class contains a given member, except that given member's name is supplied as an std::string. Here is an example of the situation I am in:
class MyClass {
public:
int a;
int b;
int c;
void Handle_Class(std::string prop) {
if (this->prop) { //pseudo code of what I want to accomplish
//do stuff
};
};
} my_class;
int main() {
my_class.Handle_Class("a");
};
I know Handle_Class is not the best name for a function like this, but it is basically supposed to check if the class has a member called prop. I have no idea how to actually do this though. Essentially I am trying to dynamically check if a class has a given member. I have a lot of experience in Lua, and you could easily accomplish this in Lua (although Lua is not object oriented, you could accomplish this using tables)
local my_table = {a = 123; b = 456; c = 789};
local function Handle_Table(prop)
if my_table[prop] then
print("property "..prop.." exists inside my_table!");
end
end
I would appreciate any help. Thanks