Technical Discussion :: C++
Home > Technical Interview Q&A > C++ > Discussion
100 / 187
Why do we need virtual function?
Answer:
When a function is made virtual, c++ determines which function to use at run-time based on the type of the object pointed to by the base pointer, rather than the type of the pointer. By making the base pointer to point to different objects, we execute different versions of the virtual function.
Asked In ::
Manoj
23 Feb, 2019 5:07 AM
When a function is made virtual, c++ determines which function to use at run-time based on the type of the object pointed to by the base pointer, rather than the type of the pointer. By making the base pointer to point to different objects, we execute different versions of the virtual function.