C++ 中的保留關鍵字?


保留字是指不能用作識別符號的單詞,例如變數、函式或標籤的名稱——它被“保留不用”。這是一個語法定義,保留字可能沒有意義。

C++ 中共有 95 個保留字。C++ 的保留字可以方便地分為幾組。在第一組中,我們列出了那些也存在於 C 程式語言中並被帶入 C++ 的保留字。其中有 32 個。

另外還有 30 個保留字在 C 中不存在,因此是 C++ 程式語言的新增內容。

有 11 個 C++ 保留字在使用標準 ASCII 字元集時不是必需的,但它們已被新增以提供一些 C++ 運算子的可讀性更高的替代方案,以及方便使用缺少 C++ 所需字元的字元集的程式設計。

以下是所有這些保留字的列表:

alignas (自 C++11 起)
alignof (自 C++11 起)
and
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
co_await (協程 TS)
co_return (協程 TS)
co_yield (協程 TS)
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


更新於: 2020年6月19日

9K+ 次檢視

開啟你的 職業生涯

透過完成課程獲得認證

開始學習
廣告
© . All rights reserved.