title: Access a member in a struct via a variable in C++
body: <p>I have a struct with two members, for example:</p>
  
  <pre><code>struct DataSet {
      int x;
      int y;
  };
  </code></pre>
  
  <p>..., and i have to access those in a method, but only one at a time, for example:</p>
  
  <pre><code>void foo(StructMember dsm) { // ("StructMember" does not exist)
      DataSet ds;
      ds.x = 4;
      ds.y = 6;
  
      std::cout &lt;&lt; ds.dsm * ds.dsm &lt;&lt; std::endl;
  }
  </code></pre>
  
  <pre><code>foo(x);
  foo(y);
  </code></pre>
  
  <p>Output i wish to have:</p>
  
  <pre><code>16
  36
  </code></pre>
  
  <p>What should I do when I have to solve a problem like this? Is there a data type which can access a member?</p>