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 |
[edit] Syntax
function_declaration final ;
|
|||||||||
class class_name final base_classes
|
|||||||||
This section is incomplete Reason: function_declaration is probably wrong terminology |
[edit] 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.
[edit] 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 { };
[edit] See also
- override specifier (since C++11)