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
Post a Comment