Nik*_*iou 103 c++ keyword c++11 c++14
C++标准委员会倾向于回避在该语言中添加新的关键字,但C++ 11并非如此.一些例子:
constexpr
decltype
thread_local
auto // New usage
noexcept
nullptr
static_assert
alignof
alignas
Run Code Online (Sandbox Code Playgroud)
C++ 14是否引入了新的关键字?
T.C*_*.C. 136
表4(关键词)在N3936(C++ 14)中:
alignas continue friend register true
alignof decltype goto reinterpret_cast try
asm default if return typedef
auto delete inline short typeid
bool do int signed typename
break double long sizeof union
case dynamic_cast mutable static unsigned
catch else namespace static_assert using
char enum new static_cast virtual
char16_t explicit noexcept struct void
char32_t export nullptr switch volatile
class extern operator template wchar_t
const false private this while
constexpr float protected thread_local
const_cast for public throw
Run Code Online (Sandbox Code Playgroud)
N3337(C++ 11)中的表4:
alignas continue friend register true
alignof decltype goto reinterpret_cast try
asm default if return typedef
auto delete inline short typeid
bool do int signed typename
break double long sizeof union
case dynamic_cast mutable static unsigned
catch else namespace static_assert using
char enum new static_cast virtual
char16_t explicit noexcept struct void
char32_t export nullptr switch volatile
class extern operator template wchar_t
const false private this while
constexpr float protected thread_local
const_cast for public throw
Run Code Online (Sandbox Code Playgroud)
......这是一种啰嗦的说"不"的方式.
(override
并且final
是"具有特殊含义的标识符"并在表3中列出; and
等等是"替代表示...对于某些运算符和标点符号"并列在表5中.在C++ 11和C++之间都没有更改表14.)
Jac*_*ley 33
使用C++ 14不会添加任何新关键字.这并不令人惊讶,因为C++ 14旨在作为对C++ 11的小型升级,主要涉及清理错误并进行小的,低影响的改进.下一个重大变化可能是C++ '17',我再次期待新的关键词.
C++标准委员会倾向于回避在该语言中添加新的关键字,但C++ 11并非如此.
我认为值得考虑的是为什么委员会不愿意添加新的关键词(并且偶然地为什么你错误地列入auto
你的名单).新关键字的主要问题是,在C++中,您不能使用关键字作为标识符,这意味着添加新关键字会破坏现有代码.再利用auto
,那么,不打破他们的规则,因为没有现成的代码可以使用auto
作为标识符反正.
因此,为了接受一个新的关键字,需要有一个理由超过与现有代码潜在冲突的成本,并且没有合理的方法来实现没有新关键字的相同的事情.在C++ 11的情况下,委员会接受了一些需要新关键字的提案,因为他们觉得这个好处超过了成本,而不是因为他们不讨厌添加新关键字.
这也是为什么,如果你向下看你给出的列表,每个都是一个复合关键字,因为这减少了它们与现有标识符冲突的可能性.