+ 1
Why for late binding,virtual function is required?
late binding and virtual function
1 Antwort
+ 1
A virtual function isn't the only way to achieve late binding, the same can be achieved with function pointers.
Virtual functions induce late binding because the function that might actually get called due to polymorphism might be completely different than the one associated to the current static type known to the compiler.
The compiler has to look up the virtual function table at runtime and determine the correct method to call.
Function pointers induce late binding because the compiler can't know what function is bound to the function pointer and thus it has to do late binding.