c++ - When should a non-virtual method be redefined? -


virtual methods part of c++ implementation of polymorphism. other avoiding overhead associated rtti** , method lookups, there compelling reason omit virtual?

assuming virtual added base class @ time, purpose redefining non-virtual method serve?

**whether it's measurable on modern cpus or not irrelevant question.

well, there little reasons redefining function no virtual. in fact recommend against looks same function call on exact same object behave differently based on static type of pointer/reference used.

overriding virtual member function allows specialize behavior of derived type. overloading non-virtual member function instead provide alternative behavior, in might not obvious casual reader of functions/behaviors executed.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -