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

c++, c++11

Solution

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

Problem

If I have the code: ``` struct Parent { virtual void fn(); }; struct Child : public Parent { virtual void fn() override final { Parent::fn(); } }; ``` is there a way to have `Parent::fn` be `final` only when accessed through `Child` without re-implementing `fn`, so that some other `class` can override `fn` when deriving from `Parent` but not when deriving from `Child`? like: ``` struct Child : public Parent { virtual void fn() override final = Parent::fn; }; ``` or some other syntax?

Original source