C++ 关键词

这是 C++ 中的保留字列表。因为它们为语言所用,故这些关键词不可用于重定义或重载。

alignas (C++11 起)
alignof (C++11 起)
and
and_eq
asm
atomic_cancel (TM TS)
atomic_commit (TM TS)
atomic_noexcept (TM TS)
auto(1)
bitand
bitor
bool
break
case
catch
char
char16_t (C++11 起)
char32_t (C++11 起)
class(1)
compl
concept (C++20 起)
const
constexpr (C++11 起)
const_cast
continue
decltype (C++11 起)
default(1)
delete(1)
do
double

dynamic_cast
else
enum
explicit
export(1)
extern(1)
false
float
for
friend
goto
if
import (模块 TS)
inline(1)
int
long
module (模块 TS)
mutable(1)
namespace
new
noexcept (C++11 起)
not
not_eq
nullptr (C++11 起)
operator
or
or_eq
private
protected
public
register(2)

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
thread_local (C++11 起)
throw
true
try
typedef
typeid
typename
union
unsigned
using(1)
virtual
void
volatile
wchar_t
while
xor
xor_eq

注意 andbitororxorcomplbitandand_eqor_eqxor_eqnotnot_eq (还有双标符 <%%><::>, %:%:%:)提供另一种表示标准记号的方法

除了关键词,还有拥有特殊含义的标识符,它们可用作对象或函数名,但在某些语境拥有特殊含义。

override (C++11)
final (C++11)
transaction_safe (TM TS)
transaction_safe_dynamic (TM TS)

还有,所有在任何位置含双下划线 __ 的标识符和以下划线后随大写字母开始的标识符始终受保留,而所有以单下划线开始的标识符在全局命名空间为用作名称而保留。更多以细节见标识符

命名空间 std 用于放置标准 C++ 库的名称。关于添加名称到它的规则,见扩充命名空间 std

名称 posix 为顶级命名空间保留。若程序于该命名空间声明或定义任何内容,则行为未定义。 (C++11 起)

预处理器在预处理器语境中识别下列记号:

if
elif
else
endif
defined

ifdef
ifndef
define
undef

include
line
error
pragma

预处理器在预处理器指令的语境识别下列记号:

_Pragma(C++11 起)

参阅

C 关键词C 文档

版本历史

  • (当前 | 先前 2017年7月25日 (二) 05:41Fruderica讨论 | 贡献 . . (5,219字节) (0). . (撤销)
  • 当前 | 先前 2017年7月25日 (二) 05:40Fruderica讨论 | 贡献 . . (5,219字节) (-290). . (C++20) (撤销)
  • 当前 | 先前 2017年1月23日 (一) 04:25Lynnboy讨论 | 贡献 . . (5,509字节) (-2). . (撤销)
  • 当前 | 先前 2017年1月23日 (一) 04:23Lynnboy讨论 | 贡献 . . (5,511字节) (0). . (撤销)
  • 当前 | 先前 2017年1月23日 (一) 04:23Lynnboy讨论 | 贡献. . (5,511字节) (+897). . (撤销)
  • 当前 | 先前 2016年1月3日 (日) 02:50Fefe讨论 | 贡献. . (4,614字节) (+1,363). . (撤销)
  • 当前 | 先前 2013年8月1日 (四) 08:41P12bot讨论 | 贡献 . . (3,251字节) (+19). . (r2.7.4) (机器人添加:ko:cpp/keyword (撤销)
  • 当前 | 先前 2013年7月23日 (二) 06:08P12讨论 | 贡献. . (3,232字节) (-1,181). . (translation has been verified -- rm original text) (撤销)
  • 当前 | 先前 2013年7月23日 (二) 05:46122.96.140.151讨论. . (4,413字节) (-20). . (撤销)
  • 当前 | 先前 2013年7月9日 (二) 03:04P12bot讨论 | 贡献 . . (4,433字节) (+6). . (Allow search engines to index popular pages.) (撤销)
  • 当前 | 先前 2012年11月2日 (五) 14:36P12bot讨论 | 贡献 . . (4,427字节) (+19). . (r2.7.3) (机器人添加:de:cpp/keyword, en:cpp/keyword 去除:zh:cpp/keyword (撤销)
  • 当前 | 先前 2012年10月26日 (五) 13:41P12讨论 | 贡献 . . (4,408字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 07:00TranslationBot讨论 | 贡献. . (4,408字节) (-34). . (Translated from the English version using Google Translate) (撤销)
  • 当前 | 先前 2012年10月25日 (四) 14:46P12讨论 | 贡献 . . (4,442字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前 2012年10月25日 (四) 13:00TranslationBot讨论 | 贡献. . (4,442字节) (-2,227). . (Translated from the English version using Google Translate) (撤销)
  • 当前 | 先前 2012年6月11日 (一) 16:40171.37.68.210讨论. . (6,669字节) (+168). . (a lot of the old keywords have changed since C++11) (撤销)
  • 当前 | 先前 2012年6月11日 (一) 16:13171.37.68.210讨论. . (6,501字节) (+304). . (missing keywords + formatting) (撤销)
  • 当前 | 先前 2012年5月4日 (五) 15:24P12bot讨论 | 贡献 . . (6,197字节) (+172). . (r2.7.3) (机器人添加:ar, en, es, fr, it, ja, pl, pt, ru) (撤销)
  • 当前 | 先前 2012年5月1日 (二) 09:06P12bot讨论 | 贡献. . (6,025字节) (-34). . (撤销)
  • 当前 | 先前 2012年5月1日 (二) 04:37P12讨论 | 贡献 . . (6,059字节) (0). . (1个修订: Import from Dokuwiki) (撤销)
  • 当前 | 先前) 2012年5月1日 (二) 04:37P12讨论 | 贡献. . (6,059字节) (+6,059). . (Import from dokuwiki)