title: Is there a way to get the C++ virtual member function address
body: <p>I searched this article:
  <a href="https://stackoverflow.com/questions/4998318/c-getting-function-virtual-address-with-member-function-pointer">C++ : Getting function virtual &#39;address&#39; with member function pointer</a></p>
  
  <p>In order to test if the virtual member function is usually at the beginning address of the object, I wrote the code as following:</p>
  
  <pre><code>#include &lt;pwd.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdio.h&gt;
  
  class Base
  {
  public:
      int mBase1;
      char mBase2;
      virtual void foo()
      {
          fprintf(stderr,"Base foo called\n");
      }
  };
  
  class Child: public Base
  {
  public:
      int cc;
      virtual void foo()
      {
          fprintf(stderr,"Child foo called");
      }
  };
  
  
  int main(int argc, char *argv[])
  {
      Base bb;
      fprintf(stderr,"[mBase1 %p][mBase2 %p] [foo %p]\n",&amp;bb.mBase1,&amp;bb.mBase2,&amp;Base::foo);
      return 0;
  }
  </code></pre>
  
  <p>when compiling, I got a warning:</p>
  
  <pre><code>test.cpp:30:88: warning ‘%p’ expects argument of type ‘void*’, but argument 5 has type ‘void (Base::*)()’ [-Wformat]
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>[mBase1 0xbfc2ca38][mBase2 0xbfc2ca3c] [foo 0x1]
  </code></pre>
  
  <p>I consider it's wired. </p>
  
  <ol>
  <li><p>Is there any "pretty method" to get the member function (not static member function address?). Besides the following method, is there any other elegant way?</p>
  
  <pre><code>typedef void (Base::*Foo)();
  Foo f = &amp;Base::foo();
  </code></pre></li>
  <li><p>Why doesn't <code>&amp;Base::foo</code> get the correct C++ member address?</p></li>
  </ol>