保留字是不能用作标识符的字,例如变量名、函数名或标签名——它是“禁止使用的保留字”。这是一个语法定义,保留字可能没有任何意义。
在C++中总共有95个保留字。C++的保留字可以方便地放置到多个组中。在第一组中,我们将那些也存在于C编程语言中并已经被移植到C++中。一共有32个。
还有30个不在C中的保留字,因此对于C++编程语言来说是新的。
使用标准ASCII字符集时,有11C++保留字不是必需的,但已添加这些保留字以为一些C++运算符提供更具可读性的替代方式,并且还有助于使用缺少所需字符的字符集进行编程由C++编写。
这是所有这些保留字的列表-
alignas(sinceC++11)
| alignof(sinceC++11)
| and
| and
| and_eq
| asm
|
atomic_cancel(TMTS)
| atomic_commit(TMTS)
| atomic_noexcept(TMTS)
|
auto(1)
| bitand
| bitor
|
bool
| break
| case
|
catch
| char
| char16_t(sinceC++11)
|
char32_t(sinceC++11)
| class(1)
| compl
|
concept(sinceC++20)
| const
| constexpr(sinceC++11)
|
const_cast
| continue
| co_await(coroutinesTS)
|
co_return(coroutinesTS)
| co_yield(coroutinesTS)
| decltype(sinceC++11)
|
default(1)
| delete(1)
| do
|
double
| dynamic_cast
| else
|
enum
| explicit
| export(1)
|
extern(1)
| false
| float
|
for
| friend
| goto
|
if
| import(modulesTS)
| inline(1)
|
int
| long
| module(modulesTS)
|
mutable(1)
| namespace
| new
|
noexcept(sinceC++11)
| not
| not_eq
|
nullptr(sinceC++11)
| operator
| or
|
or_eq
| private
| protected
|
public
| register(2)
| reinterpret_cast
|
requires(sinceC++20)
| return
| short
|
signed
| sizeof(1)
| static
|
static_assert(sinceC++11)
| static_cast
| struct(1)
|
switch
| synchronized(TMTS)
| template
|
this
| thread_local(sinceC++11)
| throw
|
true
| try
| typedef
|
typeid
| typename
| union
|
unsigned
| using(1)
| virtual
|
void
| volatile
| wchar_t
|
while
| xor
| xor_eq
|