I've got a struct "margin" in my class with 4 properties. Instead of writing four different getter/setter methods, I figured I could do it in a better way:
class myClass {
private:
struct margin {
int bottom;
int left;
int right;
int top;
}
public:
struct getMargin();
void setMargin(string which, int value);
};
But how can I set the property of the struct corresponding with the string "which" from within the function setMargin()
? For example, if I call myClass::setMargin("left", 3)
, how can I then set "margin.left" to "3"? Preferably while keeping the struct POD? I really can't figure this out...
And on a side note, is this really better than writing many getter/setter methods?
Thanks!