Why for late binding,virtual function is required? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why for late binding,virtual function is required?

late binding and virtual function

6th Mar 2017, 6:13 PM
Krishna Subhash Sonawane
Krishna Subhash Sonawane - avatar
1 Answer
+ 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.
6th Mar 2017, 6:30 PM
Alexandre Sabourin
Alexandre Sabourin - avatar