final
和override
struct A
{
//A::foo is final 限定该虚函数不能被重写
virtual void foo() final;
//Error: non-virtual function cannot be final,只能修改虚函数
void bar() final;
};
struct B final : A //struct B is final
{
//Error: foo cannot be overridden as it‘s final in A
void foo();
};
struct C : B //Error: B is final
{
};
struct A
{
virtual void func() {}
};
struct D : A{
//显式重写
void func() override
{
}
};
原文:https://www.cnblogs.com/fewolflion/p/12968629.html