title: Why is vptr stored as the first entry in the memory of a class with virtual functions?
body: <p>For some compilers, if a class has virtual functions then its vptr can be accessed with the address of the first byte of its object. For instance,</p>
  
  <pre><code>class Base{
  public:
      virtual void f(){cout&lt;&lt;"f()"&lt;&lt;endl;};
      virtual void g(){cout&lt;&lt;"g()"&lt;&lt;endl;};
      virtual void h(){cout&lt;&lt;"h()"&lt;&lt;endl;};
  };
  
  int main()
  {   
     Base b;
  
     cout&lt;&lt;"Address of vtbl："&lt;&lt;(int *)(&amp;b)&lt;&lt;endl;
  
     return 0;
  }
  </code></pre>
  
  <p>I know that it is dependent on different compiler behaviors. Since there is the case where vptr is stored as the very first entry, what is the advantage of doing this? Does that help improve performance or simply because it's easier to access vbtl using &amp;b? </p>