How does a C++ object know where it’s member function definitions are present? I am quite confused as the Object itself does not contain the function pointers.
sizeof on the Object proves this.
So how is the object to function mapping done by the Runtime environment? where is a class’s member function-pointer table maintained?
How does a C++ object know where it’s member function definitions are present? I
Share
If you’re calling non-virtual functions, there’s no need for a function-pointer table; the compiler can resolve the function addresses at compile-time. So:
translates to something along the lines of:
Calling a virtual function through a base-class pointer typically uses a vtable. So:
translates to something along the lines of:
where
p_vtblis a compiler-implemented pointer to the vtable specific to the actual class of*p_a.