Why is vptr stored as the first entry in the memory of a class with virtual functions?
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, class Base{ public: virtual void f(){cout<<"f()"<<endl;}; virtual void g(){cout<<"g()"<<endl;}; virtual void h(){cout<<"h()"<<endl;}; }; int main() { Base b; cout<<"Address of vtbl:"<<(int *)(&b)<<endl; return 0; } 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