cpp/language/final

Specifies that a cannot be overridden in a derived class, or that a class cannot be.

Syntax
When applied to a member function, the identifier appears immediately after the  in the syntax of a member function declaration or a member function definition inside a class definition.

When applied to a class, the identifier appears at the beginning of the class definition, immediately after the name of the class.

@1@ In a member function declaration, may appear in  immediately after the declarator, and before the, if used. @2@ In a member function definition inside a class definition, may appear in  immediately after the declarator and just before. @3@ In a class definition, may appear as  immediately after the name of the class, just before the colon that begins the, if used.

In the cases, , if used, is either or , or  or. In the case, the only allowed value of , if used, is.

Explanation
When used in a virtual function declaration or definition, specifier ensures that the function is virtual and specifies that it may not be overridden by derived classes. The program is ill-formed (a compile-time error is generated) otherwise.

When used in a class definition, specifies that this class may not appear in the  of another class definition (in other words, cannot be derived from). The program is ill-formed otherwise (a compile-time error is generated). can also be used with a definition, in which case it has no effect, since unions cannot be derived from.

is an identifier with a special meaning when used in a member function declaration or class head. In other contexts, it is not reserved and may be used to name objects and functions.

Note
In a sequence of the following tokens: the third token in the sequence is always considered as a specifier instead of an identifier:
 * one of, and ;
 * a possibly qualified ;
 * one of and {{c|{}},
 * one of and {{c|{}},