title: Upcasting a pointer to data member and its polymorphic behavior
body: <p>I am trying to cast a pointer to data member of derived class to a pointer to data member of  base class, but the following code does not compile:</p>
  
  <pre><code>class Base 
  {
  public:
      virtual void f() {}
  };
  
  class Derived : public Base 
  {
  public:
      void f() override {}
  };
  
  class Enclosing
  {
  public:
      Derived member;
  };
  
  int main()
  {
      Derived Enclosing::*p = &amp;Enclosing::member;
      auto bp = static_cast&lt;Base Enclosing::*&gt;(p); // compile error
  }
  </code></pre>
  
  <p>So I used <code>reinterpret_cast</code> instead, and the code compiles:</p>
  
  <pre><code>auto bp = reinterpret_cast&lt;Base Enclosing::*&gt;(p); // passes compile
  </code></pre>
  
  <p>And I tried to use <code>bp</code> straightforwardly:</p>
  
  <pre><code>Enclosing instance;
  (instance.*bp).f(); // calls Base::f
  </code></pre>
  
  <p>This is not what I expected because the member in <code>Enclosing</code> is actually <code>Derived</code> type.
  Then I tried this:</p>
  
  <pre><code>(&amp;(instance.*bp))-&gt;f(); // calls Derived::f
  </code></pre>
  
  <p>It works on my environment, but is this behavior guaranteed?</p>