最终班级和最终成员职能

说我有基类:

struct Base
{
    virtual void foo();
};

and the derived class is final struct A final : public Base. Does it make sense to make the member functions final as well? I've seen in several places e.g.

struct A final : public Base {
    void foo() final;
}

I am not sure it provides any value in this case as if the class itself is final I guess all the member functions are final by default as well. Am I missing something? Are there any guidelines?

评论
  • 延>X
    延>X 回复

    In case a struct or a class (A in your case) is final, you cannot declare another one inheriting it. Therefore, there's no need to also declare any methods as final.

    Maybe this is a convention in some places to be clear that this method also cannot be overridden (just as a "reminder" for the final of the struct).