I've been going through this tutorial and understood it mostly except the highlighted part. The tutorial explains vpointer and vtables.
Steps are as follows, vpointer hidden in first 4 bytes of the object will be fetchedvTable of this class is accessed through the fetched vPointer
Now from the vTable corresponding function’s address will be fetched
Function will be executed from that function pointer
What I don't understand is the 3rd (bold) part. How does the compiler know which function (function address) to call from its virtual table?
Edit:
I went through this tutorial too which explains it a bit further but the original question still holds. I guess that compiler knows how to get to specific function in vtable by some pointer indexing, like vptr+4 or something. But than how a compiler knows not to overflow and not do a vptr+12 if a +12 does not exist?