0

is it correct to say that to take advantage of polymorphism at runtime, all of the base class functions that will be overriden must be virtual. If they are not, then you are really utilizing polymorphism at compile time?
Do you guys use virtual sparingly, or frequently?

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Narue
0

>is it correct to say that to take advantage of polymorphism at
>runtime, all of the base class functions that will be overriden must be virtual.
Virtual member functions are how C++ supports run-time polymorphism, so it is correct to say that to take advantage of run-time polymorphism, you need to have virtual member functions for those member functions you wish to be polymorphic.[1]

>If they are not, then you are really utilizing polymorphism at compile time?
It's generally more accurate to say that virtual member functions allow run-time polymorphism and templates allow compile time polymorphism. If you try to use run-time polymorphism but failed to define any virtual member functions, the result simply won't be polymorphic at all.

>Do you guys use virtual sparingly, or frequently?
I use inheritance very rarely, but when I do it's nearly always to implement an abstract interface, which results in at least one virtual member function.

[1] Narue uses big words and long sentences. Deal with it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.