C++ 关键字

关键字是具有特殊意义的预定义保留标识符。 它们不能用作程序中的标识符。 Microsoft C++ 保留了下列关键字。 带前导下划线的名称是 Microsoft 扩展。

__abstract 2

__alignof 运算符

__asm

__assume

__based

__box 2

__cdecl

__declspec

__delegate 2

__event

__except

__fastcall

__finally

__forceinline

__gc 2

__hook 3

__identifier

__if_exists

__if_not_exists

__inline

__int16

__int32

__int64

__int8

__interface

__leave

__m128

__m128d

__m128i

__m64

__multiple_inheritance

__nogc 2

__noop

__pin 2

__property 2

__raise

__sealed 2

__single_inheritance

__stdcall

__super

__thiscall

__try/__except, __try/__finally

__try_cast 2

__unaligned

__unhook 3

__uuidof

__value 2

__virtual_inheritance

__w64

__wchar_t, wchar_t

abstract

array

auto

bool

break

case

catch

char

Class — 类

const

const_cast

continue

decltype

default

Delegate — 委托

删除

deprecated 1

dllexport 1

dllimport 1

do

double

dynamic_cast

else

enum

enum class

enum struct

Event — 事件

显式

extern

false

finally

float

for

for each, in

friend

friend_as

gcnew

generic

goto

if

initonly

inline

int

interface class

interface struct

interior_ptr

literal

long

mutable

naked 1

namespace

new

new

noinline 1

noreturn 1

nothrow 1

novtable 1

nullptr

operator

private

属性

property 1

protected

public

ref class

ref struct

register

reinterpret_cast

return

safecast

sealed

selectany 1

short

signed

sizeof

static

static_assert

static_cast

struct

switch

Template — 模板

this

thread 1

throw

true

try

typedef

typeid

typeid

typename

union

unsigned

using declaration, using directive

uuid 1

value class

value struct

virtual

void

volatile

while

1   __declspec 关键字的扩展特性。

2   仅适用于 C++ 托管扩展。 此语法现已弃用。

3   事件处理中使用的内部函数。

有关更多信息,请参见面向 CLR 的语言功能

Microsoft 专用

在 Microsoft C++ 中,保留带有两条前导下划线的标识符以供编译器实现使用。 因此,Microsoft 约定位于带双下划线的 Microsoft 特定关键字前面。 这些单词不能用作标识符名称。

默认情况下将启用 Microsoft 扩展。 若要确保你的程序是完全可移植的,则可以通过在编译期间指定与 ANSI 兼容的 /Za 命令行选项(针对 ANSI 兼容性进行编译)来禁用 Microsoft 扩展。 如果这样做,将禁用 Microsoft 专用关键字。

启用 Microsoft 扩展后,你可以在程序中使用 Microsoft 特定关键字。 为了符合 ANSI,这些关键字的前面有一条双下划线。 出于向后兼容性考虑,支持除 __except、__finally、__leave 和 __try 以外的所有双下划线关键字的单下划线版本。 此外,还提供了没有前导下划线的 __cdecl。

__asm 关键字替代了 C++ asm 语法。 保留了 asm 以便与其他 C++ 实现兼容,但未成功。 请使用 __asm。

__based 关键字对于 32 位和 64 位目标编译的使用会受到限制。

请参见

参考

词法约定

C++ 运算符