Namespaces
Variants

C++ keywords

From cppreference.net
C++ language
General topics
Flow control
Conditional execution statements
Iteration statements (loops)
Jump statements
Functions
Function declaration
Lambda function expression
inline specifier
Dynamic exception specifications ( until C++17* )
noexcept specifier (C++11)
Exceptions
Namespaces
Types
Specifiers
constexpr (C++11)
consteval (C++20)
constinit (C++20)
Storage duration specifiers
Initialization
Expressions
Alternative representations
Literals
Boolean - Integer - Floating-point
Character - String - nullptr (C++11)
User-defined (C++11)
Utilities
Attributes (C++11)
Types
typedef declaration
Type alias declaration (C++11)
Casts
Memory allocation
Classes
Class-specific function properties
Special member functions
Templates
Miscellaneous

这是 C++ 中的保留关键字列表。由于这些关键字已被语言使用,因此无法重新定义或重载。 作为例外,在 属性 中(不包括属性参数列表)不视作保留关键字。 (since 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 not not_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 被保留用于未来的顶级命名空间。若程序在该命名空间中声明或定义任何内容,其行为是未定义的。

(since 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)

说明:根据要求保留了所有HTML标签、属性和代码标签内容,仅对页面结构进行了中文呈现。所有C++预处理器指令(如if/elif/define等)和语言特性标记(如C++23/C++26)均保持原文未翻译。

以下标记在预处理器指令 之外 的上下文中可被 预处理器 识别:

_Pragma (C++11)

参见

C 文档 关于 keywords