为什么在C ++中override是可选的? [英] Why is override optional in C++?
问题描述
我了解 C ++覆写的目的,但我的实施有点困惑
I understand the purpose of the C++ override, however am a bit confused by it's implementation compared to other higher level languages, where its use is required by default.
C ++ 11 wiki页面将其描述为声明器属性的技术标识符,但不详细说明为什么它不是简单的语言关键字。
The C++11 wiki page describes it as a "technically identifier for declarator attribute" but does not elaborate as to why it is not simply a keyword for the language.
推荐答案
这是可选的维持与C ++ 03的向后兼容性。使其不可选会破坏所有的代码 * 。
It is optional to maintain backwards compatibility with C++03. Making it non-optional would have broken all the code*.
同样,使 override
关键字会破坏使用名称 override
的任何代码。
Similarly, making override
a keyword would have broken any code that used the name override
.
OK,不是字面上的全部代码,但很多。
OK, not literally all the code, but a lot of it.
这篇关于为什么在C ++中override是可选的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!