The -> operator
-> operator — shorthand for dereferencing a pointer and accessing a member. Equivalent to (*pointer).member. Building a class with a header file
enum class
You can think of these as a variable, but ahead of time it is constrained to a specific set of values. Definition of a Dangling Pointer
Dangling pointer — a pointer that points to memory that no longer belongs to you. The object it pointed to has been destroyed, but the pointer still holds its old address. Address of Operator
Definition of a Caller
Caller — the function that calls another function. Passing Functions (Callbacks)
In C++, functions can be passed as parameters to other functions using function pointers, allowing you to decide what code runs without hardcoding it. The receiving function holds onto the address of the passed function and calls it at the right time. This is the foundation of event-driven programming, where you say "call this function when something happens" namespace alias
Creates a shorthand alias for a long namespace to make code less verbose. The alias can be used anywhere in the file in place of the full namespace name. Commonly used for long standard library namespaces like std::filesystem. const placed after a member function
A const placed after a method signature means the function is read-only — it cannot modify any member variables of the object. It acts as a guardrail, forcing the compiler to catch accidental modifications inside the function. Use it on any method that only needs to read state, such as getters, to make your intent clear and your code safer. Default parameter values
static_cast
A C++ operator that explicitly converts a value from one type to another at compile time, making the conversion visible and intentional in the code. It is safer than a C-style cast because the compiler checks that the conversion is valid. It is used when you need to convert between related types such as int and float, or long and int. Direct versus copy initialization of a constructor
Direct initialization T b(a) and copy initialization T b = a are two syntax styles that both invoke the copy constructor to create a new object from an existin…Direct initialization T b(a) and copy initialization T b = a are two syntax styles that both invoke the copy constructor to create a new object from an existing one. They produce the same result — a new object constructed as a copy of a. Access Modifiers
Controls who can access members (variables and functions) of a class. public — accessible from anywhere. protected — accessible only within the class and any class that inherits from it. private — accessible only within the class itself, not even by children. constexpr
Declares that a value is constant and must be known at compile time. Stronger than const — the compiler evaluates it before the program runs. Allows the compiler to make deeper optimisations than const alone. override
Tells the compiler you are intentionally overriding a virtual function from a parent class. If the function signature doesn't match the parent's virtual function exactly, the compiler will error. Without it, a typo or signature mismatch would silently create a new function instead of overriding the parent's. Integer Literal Suffixes
Suffixes added to integer literals to specify their type explicitly. Used to avoid signed/unsigned mismatch warnings when comparing with typed values. Common suffixes are u for unsigned, l for long, and ul for unsigned long. |
Defnition of a Thread
An independent sequence of execution within a program. The OS can run multiple threads concurrently, each doing their own work, while sharing the same memory. L values (Left Values)
An lvalue (locator value) is an expression that refers to a memory location and can appear on the left-hand side of an assignment. It represents an object that persists beyond a single expression — it has an identifiable address in memory. Definition of a Static Method
A static method is a function that belongs to the class itself rather than to any instance of it. It has no access to instance attributes and can be called without ever creating an object. Definition of a Signature
A function signature in C++ is the part of a function declaration that identifies it uniquely to the compiler. It consists of: Function name Parameter types (number, order, and types) Reference declaration (in type declarations)
Endless For-Loop
Macros
A preprocessor directive defined with #define that is expanded before the compiler sees the code. It is not a function or a class, and can be used for text substitution, constants, or conditional compilation. Macros are considered old fashioned in modern C++ but are still used in cases where compile time behaviour is needed. Passing This to Other Objects
Anytime a class the keyword "this" is implicit and automatic. Once a class has to pass data from the class into another object the "this" keyword has to be passed. The Two Main Ways of Initializing a Function
bitwise OR assignment operator
Bitwise OR assignment (|=) — takes the existing bits of the left operand, ORs them column by column with the bits of the right operand, and stores the result b…Bitwise OR assignment (|=) — takes the existing bits of the left operand, ORs them column by column with the bits of the right operand, and stores the result back into the left operand. Can only turn bits on, never off. Operator=
operator= defines what happens when you use = on an object.operator= defines what happens when you use = on an object. It takes a reference to another object of the same type and returns a reference to itself via return *this, enabling chained assignments like c = b = a. For Loop with Internal Cursor
Used when the object being read maintains its own internal cursor that advances automatically with each read. The condition of the for loop both reads the next item AND advances the cursor in one step, so no increment is needed. Only works with stream objects like std::ifstream, std::cin etc. that consume data sequentially. Global Namespace ::
A leading :: tells the compiler to start looking from the global namespace rather than the current one. Used to avoid ambiguity when a name might exist in both the current namespace and the global namespace. Without it the compiler searches the current namespace first, which could resolve to the wrong type. const
Declares that a variable's value cannot be modified after initialisation. Can be applied to variables, pointers, and function parameters. Enforced at runtime. char*
A pointer to a character, typically used to point to the start of a string. Strings in C are just arrays of characters ending with a null terminator \0 — reading a string means reading every character from the pointer until \0 is reached. Adding a number to the pointer moves it forward by that many characters, changing where reading begins. Inheritance
Allows a class to inherit members and behaviour from a parent class using :. public inheritance means the parent's public members stay public in the child. private inheritance means the parent's public members become private in the child. Use :: before the parent class name to explicitly reference the global namespace. |
Lambda Functions
The brackets tell the lambda which variables from the surrounding scope it's allowed to use, and how it remembers them. By default, a lambda body cannot see any local variable from the function it's written inside. The capture list is how you grant access, one variable (or one default rule) at a time. Constructing an obect in C++
This is how it would look in Python: variable_name = ClassName(constructor_arguments) Dereferencing a Pointer
The * in front of a pointer means "go to the address this pointer holds and give me what's there." Range Based For-Loops
A range-based for loop is a loop that iterates over every element in a collection, from the first to the last, without needing to manually manage an index or i…A range-based for loop is a loop that iterates over every element in a collection, from the first to the last, without needing to manually manage an index or iterator. const — omit if you need to modify <element> & — omit if you want a copy of each element rather than a reference Template Functions
Try Catch
catch(...). This is for any unkown exception that can't be caught by an std::exception. Template Aliases
Factory Method
A static method that constructs and returns an object, hiding the construction details from the caller. =delete
= delete explicitly forbids a function from being used, turning a potential runtime crash into a compile time error.= delete explicitly forbids a function from being used, turning a potential runtime crash into a compile time error. constexpr
constexpr declares a value that is fixed and known at compile time, meaning the compiler bakes it directly into the binary rather than storing it in memory. This eliminates any runtime cost of looking up the value, since the compiler simply substitutes it wherever it appears in the code. It also makes intent explicit — clearly signaling to other developers that this value is a compile time constant that will never change. Member Initializer List
A way to set a class's member variables before the constructor body runs. Uses a colon after the constructor parameters, with each member and its starting value in parentheses. std::move can be used instead of copying when transferring ownership of data. What goes in the (): The value you want the member to start with. This is usually the matching constructor parameter, but can also be a literal value like 0 or "default". static
Signals that a value belongs to the class, not any instance, and is fixed at compile time. Definition of a Non-Static Member Function
A non-static member function is a function that belongs to a specific instance of a class, and always operates on that instance through this. Commenting Out Unused Parameters in C++
When a function signature is fixed and you can't change it, but don't need all the parameters, comment out the name to suppress unused warnings while keeping the type. R"delimiter(...)delimiter"
Used when a string contains special characters like $, ", \, or newlines that would need escaping in a regular string. Everything between the delimiters is treated as literal text — no escape sequences are processed. The delimiter can be any text but must be unique enough to not appear inside the string content, and is often chosen to hint at the content type (e.g. sh for shell scripts, html for HTML). Virtual Function
A function in a base class that is designed to be overridden by child classes. The override keyword confirms to the compiler that you are intentionally overriding a parent function. Without virtual in the parent, the child's version would not be called polymorphically. std::function
A general purpose wrapper that can hold any callable — a function, lambda, or function object. The template parameter describes the function signature: return type and argument types. Useful for storing and passing functions as variables. |
Cheatography
https://cheatography.com
C++ Cheat Sheet (DRAFT) by blakecromar
A cheatsheet for C++
This is a draft cheat sheet. It is a work in progress and is not finished yet.