Skip to content

Key Keywords and Builtins

deprecated

Used to throw a warning when a function or method is called to specify that it is deprecated.

c++
[[deprecated("Not thread-safe, use alternative x instead.")]]
char *receive(const std::string &topic);
[[deprecated("Not thread-safe, use alternative x instead.")]]
char *receive(const std::string &topic);

static

This keyword operates differently depending on whether it modifies a classes member data or member functions.

Data members When a data member is declared static, there is only one copy of the data, independent of the number of instances of the class. In other words, a static member is shared by all members of the class. A static data member may be useful to track the number of instances of the class.

Function members Static member functions are more intuitive. They belong to the class, but don't have access to the internal members of the class. That is, they cannot call non-static functions of the class, and don't have access to the this pointer. This concept is akin to a Python class method not having self as the first argument. A static function member may be useful to logically associate functionality with a class, but keep it otherwise isolated.

typedef & using

Short for type definition, this keyword allows the user to create new names for types. It is commonly used in C++ to redefine template types.

Usage

c++
typedef existing_type new_type;
typedef existing_type new_type;

A more recent addition to create type aliases in C++ is the using keyword.

Usage

c++
using new_type_name = existing_type;
using new_type_name = existing_type;

noexcept

Incomplete... to be filled.

nodiscard

incomplete...

explicit

Incomplete...

constexpr

Specifies a constant expression. Can be applied to variables or functions. Indicates that the value, or return value, is constant and is computed at compile time.

override

The override specifier is applied to a member function of a class and is used to ensure that the function is virtual and is overriding a virtual function from a base class. If this isn't true a sompile-time error is thrown.

decltype