title: Is it okay to cast a pointer-to-member-variable in this instance?
body: <p>I've been refreshing/updating my knowledge of C++ lately, and learning about strict aliasing has made me a bit wary of casting pointers of one type to another.  I know that this following code sample works in practice on my compiler, but I want to make sure that it conforms to current standards:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  class MyBase {
  
      public:
      virtual void DoSomething() = 0;
  
  };
  
  class MyDerived1 : public MyBase {
  
      public:
      virtual void DoSomething() {
          cout &lt;&lt; "I'm #1" &lt;&lt; endl;
      }
  
  };
  
  class MyDerived2 : public MyBase {
  
      public:
      virtual void DoSomething() {
          cout &lt;&lt; "I'm #2" &lt;&lt; endl;
      }
  
  };
  
  template &lt;typename Base, typename Member1, typename Member2&gt;
  struct Tuple {
  
      public:
      Base* Get(int i) {
          return &amp;(this-&gt;*(lookupTable[i]));
      }
  
      private:
      Member1 member1;
      Member2 member2;
  
      static Base Tuple::* const lookupTable[2];
  
  };
  
  template &lt;typename Base, typename Member1, typename Member2&gt;
  Base Tuple&lt;Base, Member1, Member2&gt;::* const Tuple&lt;Base, Member1, Member2&gt;::lookupTable[2] = {
      reinterpret_cast&lt;Base Tuple&lt;Base, Member1, Member2&gt;::*&gt;(&amp;Tuple::member1),
      reinterpret_cast&lt;Base Tuple&lt;Base, Member1, Member2&gt;::*&gt;(&amp;Tuple::member2)
  };
  
  int main() {
  
      Tuple&lt;MyBase, MyDerived1, MyDerived2&gt; tuple;
  
      tuple.Get(0)-&gt;DoSomething();
      tuple.Get(1)-&gt;DoSomething();
  
      return 0;
  
  }
  </code></pre>
  
  <p>Essentially, this simple tuple contains a pair of elements, each of which should derive from a common base class.  The Get function returns a <code>Base&#42;</code> to the member that the given index represents.</p>
  
  <p>The key part that I'm wondering about is the reinterpret_casts.  I know that casting from <code>Derived Struct::&#42;</code> to <code>Base Struct::&#42;</code> is <em>generally</em> a no-no, but in this case I only use the pointers-to-member-variable to get a <em>pointer</em> to the object.  (I don't try to copy a derived object as though it were a base object, nor stuff a base object into a derived object's memory.)  This works as intended on G++, and I just want to be sure that I'm not going to get bitten by any compliant compilers for doing this.</p>