This is a design question, let's have a simple method:
virtual void Test() { };
We can override it the same way, or even not specifying virtual
at all probably, but then there's this override
keyword, which makes the compiler check it is actually overriding something, which is useful, but it needs to be written like this:
void Test() override { };
To me this makes no sense, since I'd edit literally thousands of these methods, and as it is now, the editing would be just too clumsy to spend the time with. So what is the logic behind placing the override after, since it could be much easier and to me generally better like this:
override void Test() { };
virtual
was introduced right at the beginning of C++ as a keyword. This means you can't use it as a variable name, a class name, a function name, and so on.
override
came much later on. In order that its introduction in C++11 didn't break existing code, it doesn't quite attain the status of a keyword; rather it's called an identifier with special meaning. final
is similar.
Its curious positioning is specified by the language grammar: an example where allowing it to be at the beginning would be a breaking change is
override :: foo bar()
where override::foo
must be a qualified return type of the function bar()
rather than an overrider with a explicitly global return type ::foo
(Acknowledge @BenVoigt.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With