title: C++ template struct 'has no member named' error
body: <p>The only way I can get this to compile without issuing a warning on no member a when <code>T==B</code> and so on for <code>T==A</code> is to <code>reinterpret_cast</code> within the if statement blocks and access the non-shared members via a pointer.  Is there no way to get around this or hint to the compiler otherwise?</p>
  
  <p>This is gcc 4.8.x</p>
  
  <pre><code>enum Type { A, B};
  
  template&lt;Type T&gt; struct S { };
  template&lt;&gt; struct S&lt;A&gt; { int x; int a; };
  template&lt;&gt; struct S&lt;B&gt; { int y; int x; int b; };
  
  template&lt;Type T&gt; static void foo(int x)
  {
      // lots of code
  
      S&lt;T&gt; s;
      s.x = someCall();
  
      if (T == A)
      {
          s.a = 1;
      }
      else if (T == B)
      {
          s.y = 2;
          s.b = 3;
      }
  
      // a bunch of common code
  }
  </code></pre>
  
  <p>Edit: I know about making a dedicated specific functions to handle the specifics but I was hoping to avoid extra boilerplate code.</p>