This question already has an answer here:
这个问题在这里已有答案:
- How to enforce the 'override' keyword? 2 answers
如何强制执行'override'关键字? 2个答案
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 ++中没有这样的功能。您可以使用静态分析工具强制执行它。