title: C++ how does the compiler synthesize the default copy constructor
body: <p>The default copy constructor that is synthesized by the compiler for
  a class that does not define its own does the right thing: it copies
  all the members from one object to another. </p>
  
  <p>I want to do something similar. I want to write a method</p>
  
  <pre><code>template &lt;typename T&gt;
  T f(const T&amp; obj) {
   // for each member var i of obj, I want to call some method g(obj.i)
  }
  </code></pre>
  
  <p>Now I don't know what the names of the member variables are.  If this was
  the copy constructor, I could call the assignment operator instead of g.</p>
  
  <p>Clearly the compiler does this (but maybe it does this after it has inferred
  the name of the members of the class). Is it even possible to do this 
  for any class T ?</p>