C++ 关键字

c++programmingobject oriented programming

关键字是那些其含义已由编译器定义的词。这些关键字不能用作标识符。请注意,关键字是保留字和预定义标识符的集合。预定义标识符是由编译器定义但可由用户更改含义的标识符。 

例如,您可以在主函数内声明一个名为 main 的变量,对其进行初始化,然后打印出其值(但只能这样做以验证您是否可以!)。另一方面,您不能对名为 else 的变量执行此操作。区别在于 else 是保留字,而 main"仅"是预定义标识符。

C++ 中共有 95 个保留字。C++ 的保留字可以方便地分为几组。在第一组中,我们放入了那些也存在于 C 编程语言中并已延续到 C++ 中的保留字。一共有 32 个。

还有另外 30 个保留字,它们在 C 中是没有的,因此对 C++ 编程语言来说是新的。

有 11 个 C++ 保留字,在使用标准 ASCII 字符集时它们不是必需的,但它们被添加是为了为一些 C++ 运算符提供可读的替代方案,也是为了方便使用缺少 C++ 所需字符的字符集进行编程。

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

alignas (since C++11)
double
reinterpret_cast
alignof (since C++11)
dynamic_cast
requires (since C++20)
and
else
return
and_eq
enum
short
asm
explicit
signed
atomic_cancel (TM TS)
export(1)
sizeof(1)
atomic_commit (TM TS)
extern(1)
static
atomic_noexcept (TM TS)
false
static_assert (since C++11)
auto(1)
float
static_cast
bitand
for
struct(1)
bitor
friend
switch
bool
goto
synchronized (TM TS)
break
if
template
case
import (modules TS)
this
catch
inline(1)
thread_local (since C++11)
char
int
throw
char16_t (since C++11)
long
true
char32_t (since C++11)
module (modules TS)
try
class(1)
mutable(1)
typedef
compl
namespace
typeid
concept (since C++20)
new
typename
const
noexcept (since C++11)
union
constexpr (since C++11)
not
unsigned
const_cast
not_eq
using(1)
continue
nullptr (since C++11)
virtual
co_await (coroutines TS)
operator
void
co_return (coroutines TS)
or
volatile
co_yield (coroutines TS)
or_eq
wchar_t
decltype (since C++11)
private
while
default(1)
protected
xor
delete(1)
public
xor_eq
                       do
                  register(2)


相关文章