title: template instantiation check for member existing in class
body: <p>I have a group of classes that have one or more members of the type memberA, memberB, memberC. Not all classes have all the members. I want to create a template that will set the members such as </p>
  
  <pre><code>template &lt;typename T&gt;
  void setAttributes(t &amp; myClass, typeA memA, typeB memB, typeC memC)
  {
    myClass.memberA = memA;
    myClass.memberB = memb;
    myClass.memberC = memC;
  }
  </code></pre>
  
  <p>Obviously this will fail at compile time when attempting to instantiate a class that is missing one of the members. Is there a #if or something similar that will allow the check to be done for a conditional compile of the form</p>
  
  <pre><code>#ifdef myClass.memberA
    myClass.memberA = memA;
  #endif
  </code></pre>
  
  <p>I do not have access right now to actually try this or anything similar and I would like to know if there is a valid way of setting it up.</p>
  
  <p>I have seen references to SFINAE ("substitution failure is not an error.") but I am not sure how it would be used in this case. Is the suggestion below correct?</p>
  
  <p><a href="http://en.wikipedia.org/wiki/Substitution_failure_is_not_an_error" rel="nofollow">Substitution failure is not an error</a> example would seem to imply that I should create a separate function for each member with a duplicate function without that member. </p>
  
  <pre><code>template &lt;typename T&gt;
  void setMemberA(T &amp; myClass, typeA memA)
  {
    myClass.memberA = memA;
  }
  
  template &lt;typenum T&gt;
  void setMemberA(T &amp; myClass)
  {
    // This is a dummy template to avoid a compilation problem
  }
  </code></pre>