c++ - Is virtual final method better than non-virtual one in a root class? -
c++ - Is virtual final method better than non-virtual one in a root class? -
i have abstract class root of hierarchy of classes. root class have method trivial implementation , seems there no need alter implementation anywhere anytime.
making method non-virtual fine, there chance subclass reimplement accident. virtual final method improve solution in case?
if decide declare method virtual... final, create users pay runtime cost of virtual dispatch in order protect little number of users might accidentally hide base of operations class' function.
since 1 of guiding principles in c++ "you don't pay for you don't use," improve leave function non-virtual, , allow derivers responsible if hide function.
c++ c++11
Comments
Post a Comment