Quick Q:Is there a way to mark a parent's virtual function final from a child class?

Quick A: No.

Recently on SO:

Is there a way to mark a parent's virtual function final from a child class without reimplementing it

No, you can't do it without reimplementing it. So just reimplement it:

struct Child : public Parent
{
    virtual void fn() override final { Parent::fn(); }
};

N.B. saying virtual ... override final is entirely redundant, final is an error on a non-virtual function, so you should just say:

    void fn() final { Parent::fn(); }

See http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rh-override

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.