final specifier
From cppreference.com
Specifies that a virtual function can not be overridden in a derived class or that a class cannot be inherited
Contents |
Syntax
Template:sparam final ;
|
|||||||||
class Template:sparam final Template:sparam
|
|||||||||
This section is incomplete Reason: function_declaration is probably wrong terminology |
Explanation
When used in a virtual function declaration, final
specifies that the function may not be overridden by derived classes.
final 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.
Example
struct A { virtual void foo() final; }; struct B final : A { void foo(); // Error: foo cannot be overridden as it's final in A }; struct C : B // Error: B is final { };
See also
- override specifier (since C++11)