Namespaces
Variants
Actions

Talk:cpp/language/final

From cppreference.com

When doing a search of "final" (or "override") the result is empty!!!! (hns)

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
};

The error in "void bar() final" is that bar() does not exist in Base class. Please, correct it. Thanks!

Pablocamacho (talk) 14:23, 14 November 2020 (PST)pablocamacho

Please run this code:
struct Base
{
    virtual void foo();
};
 
struct A : Base
{
    void foo() final; // Base::foo is overridden and A::foo is the final override
    virtual void bar() final; /* See: no errors anymore :) Thus `bar()` should not
    ^^^^^^^                      necessarily be declared in Base class. */
};
 
#include <cstdio>
int main() { puts("OK"); }