命名空間
變體
動作

C++ 關鍵字

出自 cppreference.com
< cpp
 
 
C++ 語言
一般主題
關鍵字
轉義序列
流程控制
條件執行陳述式
if
疊代陳述式 (迴圈)
for
範圍 for (C++11)
跳躍陳述式
函式
函式宣告
Lambda 函式運算式
inline 指定符
動態例外規範 (直到 C++17*)
noexcept 指定符 (C++11)
例外
命名空間
型別
指定符
const/volatile
decltype (C++11)
auto (C++11)
constexpr (C++11)
consteval (C++20)
constinit (C++20)
儲存期指定符
初始化
 
 

這是 C++ 保留關鍵字列表。由於這些關鍵字被語言本身所使用,因此不能重新定義或重載它們。作為例外,在屬性(attributes)中(屬性參數列表除外)不將它們視為保留字。(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 (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 中新增語意。

請注意:andbitororxorcomplbitandand_eqor_eqxor_eqnot 以及 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 為未來的頂層命名空間所保留。若程式在該命名空間中宣告或定義任何內容,其行為是未定義的。

(C++11 起)

當處於預處理器指令(preprocessor directive)的上下文中時,預處理器會識別下列標記:

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 關鍵字
English Deutsch 日本語 中文(简体) 中文(繁體)