命名空间
变体
操作

C++ 关键词

来自 cppreference.cn
< cpp
 
 
C++ 语言
通用主题
关键词
转义序列
流程控制
条件执行语句
if
迭代语句 (循环)
for
范围for (C++11)
跳转语句
函数
函数声明
Lambda 函数表达式
inline 说明符
动态异常规范 (在 C++11 中已弃用*)
noexcept 说明符 (C++11)
异常
命名空间
类型
说明符
const/volatile
decltype (C++11)
auto (C++11)
constexpr (C++11)
consteval (C++20)
constinit (C++20)
存储期说明符
初始化
 
 

这是 C++ 中保留关键字的列表。 由于它们被语言使用,因此这些关键字不可用于重新定义或重载。 作为例外,它们在属性中不被视为保留字(不包括属性参数列表)。(自 C++11 起)

A – C D – P R – Z

alignas (C++11)
alignof (C++11)
and
and_eq
asm
atomic_cancel (TM TS)
atomic_commit (TM TS)
atomic_noexcept (TM TS)
auto (1) (3) (4) (5)
bitand
bitor
bool
break
case
catch
char
char8_t (C++20)
char16_t (C++11)
char32_t (C++11)
class (1)
compl
concept (C++20)
const
consteval (C++20) (5)
constexpr (C++11) (3)
constinit (C++20)
const_cast
continue
contract_assert (C++26)
co_await (C++20)
co_return (C++20)
co_yield (C++20)

decltype (C++11) (2)
default (1)
delete (1)
do
double
dynamic_cast
else
enum (1)
explicit
export (1) (4)
extern (1)
false
float
for (1)
friend
goto
if (3) (5)
inline (1) (3)
int (1)
long
mutable (1)
namespace
new
noexcept (C++11)
not
not_eq
nullptr (C++11)
operator (1)
or
or_eq
private (4)
protected
public

reflexpr (reflection TS)
register (3)
reinterpret_cast
requires (C++20)
return
short
signed
sizeof (1)
static
static_assert (C++11)
static_cast
struct (1)
switch
synchronized (TM TS)
template
this (5)
thread_local (C++11)
throw (3) (4)
true
try
typedef
typeid
typename (3) (4)
union
unsigned
using (1) (4)
virtual
void
volatile
wchar_t
while
xor
xor_eq

  • (1) — 意义在 C++11 中已更改或添加了新意义。
  • (2) — 在 C++14 中添加了新意义。
  • (3) — 意义在 C++17 中已更改或添加了新意义。
  • (4) — 意义在 C++20 中已更改或添加了新意义。
  • (5) — 在 C++23 中添加了新意义。

请注意:and, bitor, or, xor, compl, bitand, and_eq, or_eq, xor_eq, notnot_eq (以及双字符组:<%, %>, <:, :>, %:, %:%: 和三字符组: ??<, ??>, ??(, ??), ??=, ??/, ??', ??!, ??-(直到 C++17)) 提供 表示标准记号的备选方式 这些关键字在属性中也被视为保留字(不包括属性参数列表),但某些实现将它们与其他关键字同等对待。(自 C++11 起)

除了关键字之外,还有具有特殊含义的标识符,它们可以用作对象或函数的名称,但在某些上下文中具有特殊含义。

final (C++11)
override (C++11)
transaction_safe (TM TS)
transaction_safe_dynamic (TM TS)
import (C++20)
module (C++20)
pre (C++26)
post (C++26)
trivially_relocatable_if_eligible (C++26)
replaceable_if_eligible (C++26)

此外,所有在任何位置包含双下划线 __标识符以及每个以下划线后跟大写字母开头的标识符始终是保留的,并且所有以下划线开头的标识符都保留用于全局命名空间中的名称。 有关更多详细信息,请参见标识符

命名空间 std 用于放置标准 C++ 库的名称。 有关向其添加名称的规则,请参见扩展命名空间 std

名称 posix 保留用于将来的顶层命名空间。 如果程序在该命名空间中声明或定义任何内容,则行为是未定义的。

(自 C++11 起)

以下记号在预处理器指令的上下文中被预处理器识别

if
elif
else
endif

ifdef
ifndef
elifdef (C++23)
elifndef (C++23)
define
undef

include
embed (C++26)
line

error
warning (C++23)
pragma

defined
__has_include (C++17)
__has_cpp_attribute (C++20)
__has_embed (C++26)

export (C++20)
import (C++20)
module (C++20)

以下记号在预处理器指令外部上下文中被预处理器识别

_Pragma (C++11)

[编辑] 参见

C 文档 关于 C 关键词