名稱空間
變體
操作

C++ 關鍵字

來自 cppreference.com
< cpp
 
 
C++ 語言
 
 

這是 C++ 中的保留關鍵字列表。由於它們被語言使用,這些關鍵字不能被重新定義或過載。作為例外,它們在屬性中不被視為保留(不包括屬性引數列表)。(C++11 起)

A – C D – P R – Z

alignas (C++11)
alignof (C++11)

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 (反射 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 中新增新含義。

請注意:andbitororxorcomplbitandand_eqor_eqxor_eqnotnot_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 關鍵字