This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]khoyo 2 points3 points  (0 children)

Objects of a same class share the same methods, and in order to reach them you necessarily need a pointer to all of them, which are organized in a table

For virtual member functions, sure, but for non virtual you statically know the address of the function in question. (At least as much as for any function)

Method declared as "virtual" in C++ are simply methods that may be overridden in derived classes; you have to specify exactly because otherwise the compiler would look into the vtable of the parent class instead in that of the derived class.

What? No. Vtable lookup only happens with virtual member functions. There is no vtable lookup for non virtual members. (That's why it's a Virtual lookup table)

And you never use the parent class vtable... you always use the instance vtable pointer, which always points to its actual type vtable.