override 或 final 关键字不应与 virtual 关键字同时出现在声明中
6.3.7 ID_redundantVirtual
只应在定义新的虚函数时使用 virtual 关键字,重写虚函数应使用 override 或 final 关键字,不应再出现 virtual 关键字。
示例:
class A {
public:
virtual int foo(); // Compliant, a new virtual function
virtual int bar(); // Compliant, a new virtual function
};
class B: public A {
public:
virtual int foo() final; // Non-compliant, ‘virtual’ is redundant
virtual int bar() override; // Non-compliant, ‘virtual’ is redundant
};
去掉多余的 virtual 关键字使代码更简洁:
class B: public A {
public:
int foo() final; // Compliant
int bar() override; // Compliant
};