Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: C++
Expertise: All
Jan 7, 2000



Building the Right Environment to Support AI, Machine Learning and Deep Learning

To Virtual Or Not To Virtual?

You're probably aware of the overhead that is associated with calling a virtual member function. However, the performance penalty in this case might even be higher than you think because the comparison isn't always between static versus dynamic binding. Usually, compilers can't inline a virtual function call. Thus, the performance cost consists of the ordinary overhead associated with a function call plus the additional overhead of dynamic binding. Many programmers aren't aware of the double overhead when they declare virtual functions abundantly. As a rule, avoid declaring a member function virtual, unless it truly has to be virtual.

Danny Kalev
Thanks for your registration, follow us on our social networks to keep up-to-date