Virtual Member Functions in C++
Final Virtual Functions (since C++ 11)
When used in a virtual function declaration or definition, the final 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.
An example:
struct Base
{
virtual void foo();
};
struct A : Base
{
void foo() final; // Base::foo is overridden and A::foo is the final override
void bar() final; // Error: bar cannot be final as it is non-virtual
};
struct B : A
{
void foo() override; // Error: foo cannot be overridden as it is final in A
};