title: Access struct property by variable value
body: <p>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:</p>
  
  <pre><code>class myClass {
      private:
          struct margin {
              int bottom;
              int left;
              int right;
              int top;
          }
      public:
          struct getMargin();
          void setMargin(string which, int value);
  };
  </code></pre>
  
  <p>But how can I set the property of the struct corresponding with the string "which" from within the function <code>setMargin()</code>? For example, if I call <code>myClass::setMargin("left", 3)</code>, how can I then set "margin.left" to "3"? Preferably while keeping the struct <a href="https://stackoverflow.com/questions/146452/what-are-pod-types-in-c">POD</a>? I really can't figure this out...</p>
  
  <p>And on a side note, is this really better than writing many getter/setter methods?</p>
  
  <p>Thanks!</p>