title: Pointers to virtual member functions. How does it work?
body: <p>Consider the following C++ code:</p>
  
  <pre><code>class A
  {
  public:
        virtual void f()=0;
  };
  
  
  int main()
  {
       void (A::*f)()=&amp;A::f;
  }
  </code></pre>
  
  <p>If I'd have to guess, I'd say that &amp;A::f in this context would mean "the address of A's implementation of f()", since there is no explicit seperation between pointers to regular member functions and virtual member functions. And since A doesn't implement f(), that would be a compile error. However, it isn't.</p>
  
  <p>And not only that. The following code:</p>
  
  <pre><code>void (A::*f)()=&amp;A::f;
  A *a=new B;            // B is a subclass of A, which implements f()
  (a-&gt;*f)();
  </code></pre>
  
  <p>will actually call B::f.</p>
  
  <p>How does it happen?</p>