Keywords have fixed meaning defined by the C++ standard and cannot be used as identifiers. It is illegal to redefine keywords using the preprocessor in any translation unit that includes a standard library header. However, keywords lose their special meaning inside attributes.
The full list of keywords is as follows:
alignas
(since C++11)alignof
(since C++11)asm
auto
: since C++11, before C++11bool
break
case
catch
char
char16_t
(since C++11)char32_t
(since C++11)class
const
constexpr
(since C++11)const_cast
continue
decltype
(since C++11)default
delete
for memory management, for functions (since C++11)do
double
dynamic_cast
else
enum
explicit
export
extern
as declaration specifier, in linkage specification, for templatesfalse
float
for
friend
goto
if
inline
for functions, for namespaces (since C++11), for variables (since C++17)int
long
mutable
namespace
new
noexcept
(since C++11)nullptr
(since C++11)operator
private
protected
public
register
reinterpret_cast
return
short
signed
sizeof
static
static_assert
(since C++11)static_cast
struct
switch
template
this
thread_local
(since C++11)throw
true
try
typedef
typeid
typename
union
unsigned
using
to redeclare a name, to alias a namespace, to alias a typevirtual
for functions, for base classesvoid
volatile
wchar_t
while
The tokens final
and override
are not keywords. They may be used as identifiers and have special meaning only in certain contexts.
The tokens and
, and_eq
, bitand
, bitor
, compl
, not
, not_eq
, or
, or_eq
, xor
, and xor_eq
are alternative spellings of &&
, &=
, &
, |
, ~
, !
, !=
, ||
, |=
, ^
, and ^=
, respectively. The standard does not treat them as keywords, but they are keywords for all intents and purposes, since it is impossible to redefine them or use them to mean anything other than the operators they represent.
The following topics contain detailed explanations of many of the keywords in C++, which serve fundamental purposes such as naming basic types or controlling the flow of execution.