"puzzlecracker" <ir*********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
At what point does an object (an instance of the class that has virtual
functions) put proper function in the vtable. I dont see it how it is
run-time binding.
Base *d=new Derived (...); // let's say the both have function
// getName() declared as virtual and
//defined in the both class.
Obviously 'd' is a pointer to a an object of class D, but d considers
it as a base class and when virtual function is invoked it consults
vtable. But placing the address of the function to vtable is done at
compile time
(You mean 'd is a pointer to an object of class type Derived, not class D,
obviously.)
When a function call is made via that pointer, the run-time behavior is to
look up the function address, then call the function. That's runtime
binding. The fact that there exists a table of function addresses (or an
equivalent representation thereof), which is created at compile time, does
not alter the fact that the address of the function for that particular call
is not known until run time. If compile-time binding were being used, then
the address of the function would be hard-coded in the machine code at that
point in the code, instead of using a lookup.
-Howard