Programming‎ > ‎Language‎ > ‎C++‎ > ‎

Keywords

The Bird's the Word

This is my notes on some of the reserved keywords in C++. Look at cppreference.com for a full list.

Fundamental types
void
Used to create pointers to void (any type) and to indicate lack of return value and lack of arguments to functions.

nullptr (C++11)
Use instead of 0 or NULL.

bool - false / true
Type that holds one of the two values: true or false. They are also keywords. The value of a sizeof(bool) is implementation defined and might be different from 1.

char / wchar_t and (since C++11) char16_t / char32_t

int
Create a integer type.
  • signed / unsigned : These keywords select if it can be positive/negative or positive values only.
  • short / long / long long: Size of the int and how big values it can contain. Implementation defined.

float / double
Creates a floating point type, usually of the IEEE-754 form.

auto (C++11)
Specify that the variable that is being declared should be automatically deduced from it's initializer.


Loop constructs
do
while
for
break
continue

Conditional statements
if
else
switch, case, default(1)

User-defined types
class

struct

union

enum
Declares an enumaration, a distict type that consist of a set of namned constants. There are two kinds of enumerations: unscoped enumeration and scoped enumeration (C++11). A  unscoped is created with the keyword enum and a scoped one with the keywords enum class.
typedef

access specifiers
private
protected
public
friend

Member function specifier
virtual
Specify that a non-static member function is virtual. It will support dynamic binding and can be overridden in derived classes.

override (C++11)
Specify that a virtual functions overrides another virtual function.

Final (C++11)
Specify that a virtual function cannot be overridden or that a class cannot be inherited from.

= delete (C++11)
= defaulted (C++11)
explicit
inline


cast
dynamic_cast<>

reinterpret_cast<>

static_cast<>
Converts Y to X and return it. No checks are made that the cast is valid. If A is not related to B in any way using the pointer returned is undefined.

const_cast<>
To modify the constness of a object pointed to by a pointer const_cast is used. It can be used to set or remove const from the object. Useful when using api's that can not be modified so one needs to send in a non const pointer.

Run-time type information
RTTI is a way to allow the type of on object to be determined when the program is running.

typeid

Exceptions
try
catch
throw
noexcept (since C++11)

type qualifiers
const
Const is used to inform the compilers that something should not be allowed to change. It can be a variable, arguments to a function or a member function. The main use of const is to prevent programming mistakes. Const is like the Borg so when you start adding it to you code you will need to add it everywhere where it's needed.

http://www.cprogramming.com/tutorial/const_correctness.html

volatile
Tells the compiler that every access (read or write operation, member call, etc) to the object must be performed and can not be optimized away even if it looks like the action is reduntant. It can be used when accessing memory ports to hardware that do not act like normal memory.

mutable
Used on non-static and non-const data members of a class this tells the compiler that it is legal to assign a value to this data member from a const member function. This can be used on internal data that does not change the externally visible state of the class. One example is a class where advanced calculations are needed to get some form of data about the object. It can then be stored in a mutable variable so it can be updated any time even in a const accessor function.


Memory
delete
new

alignas (C++11)
Specifies the alignment requirement of a type or an object.

alignof (C++11)
Get the alignment requirements of a type, in bytes.

sizeof
Return the size in bytes of the object or type.

Storage
register
Hint's the compiler to place the object in a processor register. Deprecated in C++11 as the compiler does as it wish anyway.

static

extern

thread_local (C++11)


Namespace
namespace
using

Others
asm
constexpr (C++11)
decltype (C++11)
export
goto
typename
this
static_assert (C++11)

template
template

Bitwise operation

Comments