I have a margin structure in my class with 4 properties. Instead of writing four different getter / setter methods, I decided that I could do it better:
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 structure property corresponding to the "which" line of setMargin() ? For example, if I call myClass::setMargin("left", 3) , how can I set "margin.left" to "3"? Preferably, preserving the structure of the POD ? I really can't figure it out ...
And on the side of the note, is this really better than writing a lot of getter / setter methods?
Thanks!
source share