Why do we use virtual functions?

Showing Answers 1 - 1 of 1 Answers

samiksc

  • Jan 20th, 2006
 

To achieve runtime polymorphism.

For a virtual function which is defined in both the base and derived classes, the decision of which implementation to call is taken at runtime depending on the type of object, and NOT depending on the declaration type of pointer/reference.

Virtual functions slow down execution due to runtime binding -- so only those methods which will be redefined by the derived classes should be declared as virtual.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions