是否可以要求C ++`override`说明符用于虚函数? [重复]

时间:2022-11-25 16:55:03

This question already has an answer here:

这个问题在这里已有答案:

Is there any current way, or possibly planned standards change, that would allow me to require an overridden virtual function use the override keyword?

是否有任何当前的方式,或可能计划的标准更改,允许我要求覆盖的虚函数使用override关键字?

class base {
    virtual void foo() = 0; //what, if anything, can I do here so that...
}

class derived {
    void foo(); //...this is an error...
    void foo() override; //...and only this accepted
}

1 个解决方案

#1


0  

No, there is no such feature in C++. You could enforce it with a static analysis tool, perhaps.

不,C ++中没有这样的功能。您可以使用静态分析工具强制执行它。

#1


0  

No, there is no such feature in C++. You could enforce it with a static analysis tool, perhaps.

不,C ++中没有这样的功能。您可以使用静态分析工具强制执行它。