I am almost sure this has been asked before. Unfortunately, my C++ has become so rusty that I don\'t even know what to search for.
Is there an easy-to-remember rule of t
The best way to know which modifiers (or "specifiers") have to be used in which instance is to understand what each one of them means, and what they do.
const
is a part of the method's "signature". A signature consists of what the function returns, the types of its parameters, and whether it is a constant method (the const
part). That cannot be changed, and must remain as is.
Everything else, virtual
, and override
in your list, is related to the method's declaration. It's not a part of the method's signature, and can only appear in the method's declaration.
The only rule of thumb, if there is one, is that anything that's a part of the method's signature must be unchanged, when the method is not defined inline. And if it's not, it must be a part of the declaration, only (but, as with every rule of thumb, there's always an exception, the inline
keyword).
Note that default parameter values are not considered to be a part of the method's signature. Default parameter values must be specified in the declaration only. But, if the method is defined inline, the default parameter values wind up as part of the method's definition!