Dynamically changing a property of a class in C++

Working on a console application and I am trying to figure out a way that allows users to enter an object property along with a value. For example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Box{
    public:
    int height;
    int width;
    int length;
};

int main(){
    Box ab;
    string Name,value
    cin>>Name>>value;
    map<string,string> propMap
    propMap[name] = value;
}


For example if a user inputs "height" for Name and "13" as value I would like to find a way to change ab's height to 13. I want to make this work so that one can add another class and get the same functionality.

I tried looking online and I think maps are a way to do this and I tried doing that but I don't know how to proceed after/what code to write that would allow me to change it.

Note: I can't use if else statements or hardcoding to match the input to member as I want to make this extensible.
Last edited on
map<string, int*>?
propMap["height"] = &ab.height;

Or can use map of reference wrappers:
http://en.cppreference.com/w/cpp/utility/functional/reference_wrapper
Topic archived. No new replies allowed.