Why can't I obtain the (relative) address of a virtual member for an object?

Viewed 66

I've read:

How can a C++ base class determine at runtime if a method has been overridden?

and

get the real address(or index in vTable) of virtual member function

and the answers really bug me. Suppose there's a class MyClass, with some subclasses inheriting it; and that I have a MyClass* p = get_ptr_to_a_myclass().

Now, if I am able to invoke a virtual member, i.e. write p->Method() - how can it be that I can't get the address, or the address offset, of the Method method of *p? That is just inconsistent! After all, the condition for being able to invoke a function is being able to resolve/obtain its address (and knowing its signature etc.)

Please help me resolve this conundrum.

0 Answers
Related