关键字 (C++)Keywords (C++)

关键字是具有特殊意义的预定义保留标识符。Keywords are predefined reserved identifiers that have special meanings. 它们不能用作程序中的标识符。They cannot be used as identifiers in your program. Microsoft C++ 保留了下列关键字。The following keywords are reserved for Microsoft C++. 带前导下划线的名称和后跟的名称 (C++/CLI) 是 Microsoft 扩展。Names with leading underscores, and names followed by (C++/CLI) are Microsoft extensions.

__abstract 2__abstract 2 __alignof Operator 4__alignof Operator 4 __asm 4__asm 4 __assume 4__assume 4
__based 4__based 4 __box 2__box 2 __cdecl 4__cdecl 4 __declspec 4__declspec 4
__delegate 2__delegate 2 __event__event __except 4__except 4 __fastcall 4__fastcall 4
__finally 4__finally 4 __forceinline 4__forceinline 4 __gc 2__gc 2 __hook 3__hook 3
__identifier__identifier __if_exists__if_exists __if_not_exists__if_not_exists __inline 4__inline 4
__int16 4__int16 4 __int32 4__int32 4 __int64 4__int64 4 __int8 4__int8 4
__interface__interface __leave 4__leave 4 __m128__m128 __m128d__m128d
__m128i__m128i __m64__m64 __multiple_inheritance 4__multiple_inheritance 4 __nogc 2__nogc 2
__noop__noop __pin 2__pin 2 __property 2__property 2 __ptr32 4__ptr32 4
__ptr644__ptr644 __raise__raise __restrict 4__restrict 4 __sealed 2__sealed 2
__single_inheritance4__single_inheritance4 __sptr4__sptr4 __stdcall 4__stdcall 4 __super__super
__thiscall__thiscall __try_cast 2__try_cast 2 __unaligned 4__unaligned 4 __unhook 3__unhook 3
__uptr 4__uptr 4 __uuidof 4__uuidof 4 __value 2__value 2 __vectorcall 4__vectorcall 4
__virtual_inheritance 4__virtual_inheritance 4 __w64 4__w64 4 __wchar_t__wchar_t abstract(C++/CLI)abstract(C++/CLI)
alignasalignas array(C++/CLI)array(C++/CLI) autoauto boolbool
breakbreak casecase catchcatch charchar
char16_tchar16_t char32_tchar32_t classclass constconst
const_castconst_cast constexprconstexpr continuecontinue decltypedecltype
defaultdefault delegate(C++/CLI)delegate(C++/CLI) deletedelete deprecated 1deprecated 1
dllexport 1dllexport 1 dllimport 1dllimport 1 dodo doubledouble
dynamic_castdynamic_cast elseelse enumenum 枚举类enum class
enum 结构enum struct event(C++/CLI)event(C++/CLI) explicitexplicit externextern
falsefalse finallyfinally floatfloat forfor
中的 for eachfor each in friendfriend friend_asfriend_as gcnew(C++/CLI)gcnew(C++/CLI)
generic(C++/CLI)generic(C++/CLI) gotogoto ifif initonlyinitonly
inlineinline intint 接口类(C++/CLI)interface class(C++/CLI) 接口结构(C++/CLI)interface struct(C++/CLI)
interior_ptr(C++/CLI)interior_ptr(C++/CLI) 文字(C++/CLI)literal(C++/CLI) longlong mutablemutable
naked 1naked 1 namespacenamespace new(C++/CLI)new(C++/CLI) newnew
noexceptnoexcept noinline 1noinline 1 noreturn 1noreturn 1 nothrow 1nothrow 1
novtable 1novtable 1 nullptrnullptr operatoroperator privateprivate
property(C++/CLI)property(C++/CLI) property 1property 1 受保护protected publicpublic
ref 类ref class ref 结构ref struct registerregister reinterpret_castreinterpret_cast
returnreturn safecastsafecast 密封(C++/CLI)sealed(C++/CLI) selectany 1selectany 1
shortshort signedsigned sizeofsizeof staticstatic
static_assertstatic_assert static_caststatic_cast structstruct switchswitch
templatetemplate thisthis thread 1thread 1 throwthrow
truetrue trytry typedeftypedef typeidtypeid
typeidtypeid typenametypename unionunion unsignedunsigned
使用声明using declaration 使用指令using directive uuid 1uuid 1 值类(C++/CLI)value class(C++/CLI)
值结构(C++/CLI)value struct(C++/CLI) virtualvirtual voidvoid volatilevolatile
whilewhile

1扩展特性 __declspec关键字。1 Extended attributes for the __declspec keyword.

2适用于托管扩展C++仅。2 Applicable to Managed Extensions for C++ only. 此语法现已弃用。This syntax is now deprecated. 请参阅运行时平台的组件扩展有关详细信息。See Component Extensions for Runtime Platforms for more information.

3事件处理中使用的内部函数。3 Intrinsic function used in event handling.

4对于向后兼容早期版本,这些关键字可同时使用两个前导下划线和单个前导下划线的 Microsoft 扩展时启用 (默认值)。4 For backward compatibility with previous versions, these keywords are available both with two leading underscores and a single leading underscore when Microsoft extensions are enabled (the default).

Microsoft 专用Microsoft Specific

在 Microsoft C++ 中,保留带有两条前导下划线的标识符以供编译器实现使用。In Microsoft C++, identifiers with two leading underscores are reserved for compiler implementations. 因此,Microsoft 约定位于带双下划线的 Microsoft 特定关键字前面。Therefore, the Microsoft convention is to precede Microsoft-specific keywords with double underscores. 这些单词不能用作标识符名称。These words cannot be used as identifier names.

默认情况下将启用 Microsoft 扩展。Microsoft extensions are enabled by default. 若要确保你的程序是完全可移植的,可通过在编译期间指定 /Za (禁用语言扩展)选项来禁用 Microsoft 扩展。To ensure that your programs are fully portable, you can disable Microsoft extensions by specifying the /Za (Disable language extensions) option during compilation. 如果这样做,将禁用某些 Microsoft 专用关键字。When you do this, some Microsoft-specific keywords are disabled.

启用 Microsoft 扩展后,你可以在程序中使用 Microsoft 特定关键字。When Microsoft extensions are enabled, you can use the Microsoft-specific keywords in your programs. 为了符合 ANSI,这些关键字的前面有一条双下划线。For ANSI compliance, these keywords are prefaced by a double underscore. 对于向后兼容,支持许多双下划线关键字的单下划线版本。For backward compatibility, single-underscore versions of many of the double-underscored keywords are supported. 此外, __cdecl提供了没有前导下划线。In addition, __cdecl is available with no leading underscore.

__Asm关键字将替换C++asm语法。The __asm keyword replaces C++ asm syntax. 保留了 asm 以便与其他 C++ 实现兼容,但未成功。asm is reserved for compatibility with other C++ implementations, but not implemented. 使用 __asmUse __asm.

__based 关键字对于 32 位和 64 位目标编译的使用会受到限制。The __based keyword has limited uses for 32-bit and 64-bit target compilations.

结束 Microsoft 专用END Microsoft Specific

请参阅See also

词法约定Lexical Conventions
C++ 内置运算符、优先级和关联性C++ Built-in Operators, Precedence and Associativity