title: why Base class and Drive class have same virtual pointer but 2 vtable when initiate a Drive instance
body: <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  class Base {
  public:
      Base() {
          cout &lt;&lt; "In Base" &lt;&lt; endl;
          cout &lt;&lt; "Virtual Pointer = " &lt;&lt; (int*)this &lt;&lt; endl;
          cout &lt;&lt; "Address of Vtable = "
          &lt;&lt; (int*)*(int*)this &lt;&lt; endl;
          cout &lt;&lt; "Value at Vtable = "
          &lt;&lt; (int*)*(int*)*(int*)this &lt;&lt; endl;
          cout &lt;&lt; endl;
      }
  
      virtual void f1() { cout &lt;&lt; "Base::f1" &lt;&lt; endl; }
  };
  
  class Drive : public Base {
  public:
      Drive() {
          cout &lt;&lt; "In Drive" &lt;&lt; endl;
          cout &lt;&lt; "Virtual Pointer = "
          &lt;&lt; (int*)this &lt;&lt; endl;
          cout &lt;&lt; "Address of Vtable = "
          &lt;&lt; (int*)*(int*)this &lt;&lt; endl;
          cout &lt;&lt; "Value at Vtable = "
          &lt;&lt; (int*)*(int*)*(int*)this &lt;&lt; endl;
          cout &lt;&lt; endl;
      }
  
      virtual void f1() { cout &lt;&lt; "Drive::f2" &lt;&lt; endl; }
  };
  
  int main() {
  Drive d;
  return 0;
  </code></pre>
  
  <p>}</p>
  
  <p>The output of this program is</p>
  
  <pre><code>In Base
  Virtual Pointer = 0012FF7C
  Address of Vtable = 0046C08C
  Value at Vtable = 004010F0
  
  In Drive
  Virtual Pointer = 0012FF7C
  Address of Vtable = 0046C07C
  Value at Vtable = 00401217
  </code></pre>
  
  <p>Follow the code, i can see that when i create a Drive object, the Base constructor also run and show the address of virtual pointer same with Drive's virtual pointer: 0012FF7C. The weird thing is that when i dereference that address in both constructors of Base and Drive class, it pointed to different value meaning there are two vtable, one at 0046C08C and another at 0046C07C. Its very difficult to understand in structure of Drive object and also in c langue when 1 pointer point 2 address.  </p>