Share via


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

運算子

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   只適用於 Managed Extensions for C++。 這個語法現在不建議使用。

3   用於事件處理的內建函式。

如需詳細資訊,請參閱 執行階段平台的元件擴充功能

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++ 運算子