The proposal for the addition of the keywords controlling override (override
/final
) , paper N3151 , gives us some insight about this choice (emphasis mine) :
It is preferable to put such virtual control keywords at the end of
the declaration so that they don't clash with eg. return types at the
beginning of declarations.
[...]
For context-insensitive, normal keywords, it's less important where
the keywords are placed because the words are reserved. We could put
them at the beginning of declarations or at the end.
During the discussion of attributes, Francis Glassborow pointed out
that the beginning of declarations is becoming crowded. If we put the
virtual control keywords at the beginning, we can end up with examples
like the one below:
struct B
{
virtual volatile const unsigned long int f()
volatile const noexcept;
void f(int g);
};
struct D : B
{
virtual hides_name virtual_override final_overrider volatile const unsigned long int f()
volatile const noexcept;
};
Putting the new keywords at the end at least alleviates the situation
somewhat:
struct B
{
virtual volatile const unsigned long int f()
volatile const noexcept;
void f(int g);
};
struct D : B
{
virtual volatile const unsigned long int f()
hides_name virtual_override final_overrider volatile const noexcept;
};
There are people who think these control keywords should be in the
same place with virtual. As mentioned, that place is already crowded.
Note:
The C++ 11 Standard defines context sensitive keywords in section § 2.11 / 2 [lex.name] :
The identifiers in Table 3 have a special meaning when appearing in a
certain context. When referred to in the grammar, these identifiers
are used explicitly rather than using the identifier grammar
production. Unless otherwise specified, any ambiguity as to whether a
given identifier has a special meaning is resolved to interpret the
token as a regular identifier.
Table3:
final override
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…