\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{blakecromar} \pdfinfo{ /Title (c.pdf) /Creator (Cheatography) /Author (blakecromar) /Subject (C++ Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{329C91} \definecolor{LightBackground}{HTML}{F2F8F8} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{C++ Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{blakecromar} via \textcolor{DarkBackground}{\uline{cheatography.com/218070/cs/48101/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}blakecromar \\ \uline{cheatography.com/blakecromar} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 29th June, 2026.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{The -\textgreater{} operator}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Dog{\emph{ d = new Dog("Rex"); \newline \newline d-\textgreater{}bark(); // shorthand \newline (}}d).bark(); // same thing} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{-\textgreater{} operator — shorthand for dereferencing a pointer and accessing a member. Equivalent to (*pointer).member.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Building a class with a header file}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{// Foo.h \newline struct Foo \{ \newline \textless{}Type\textgreater{} \textless{}attributeName\textgreater{}; \newline \newline static \textless{}ReturnType\textgreater{} \textless{}functionName\textgreater{}(\textless{}Type\textgreater{} \textless{}variable\textgreater{}); \newline static \textless{}ReturnType\textgreater{} \textless{}functionName\textgreater{}(\textless{}Type\textgreater{} \textless{}variable\textgreater{}); \newline static \textless{}ReturnType\textgreater{} \textless{}functionName\textgreater{}(\textless{}Type\textgreater{} \textless{}variable\textgreater{}); \newline \}; \newline \newline // Foo.cpp \newline \#include "Foo.h" \newline \newline \textless{}ReturnType\textgreater{} Foo::\textless{}functionName\textgreater{}(\textless{}Type\textgreater{} \textless{}variable\textgreater{}) \newline \{ \newline // implementation \newline \} \newline \newline \textless{}ReturnType\textgreater{} Foo::\textless{}functionName\textgreater{}(\textless{}Type\textgreater{} \textless{}variable\textgreater{}) \newline \{ \newline // implementation \newline \} \newline \newline \textless{}ReturnType\textgreater{} Foo::\textless{}functionName\textgreater{}(\textless{}Type\textgreater{} \textless{}variable\textgreater{}) \newline \{ \newline // implementation \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{enum class}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{enum class \textless{}EnumName\textgreater{} \{ \textless{}Val1\textgreater{}, \textless{}Val2\textgreater{}, \textless{}Val3\textgreater{} \}; \newline \newline \textless{}EnumName\textgreater{} \textless{}var\textgreater{} = \textless{}EnumName\textgreater{}::\textless{}Val\_n\textgreater{}; // where n is an Val in the definition.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{You can think of these as a variable, but ahead of time it is constrained to a specific set of values.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Definition of a Dangling Pointer}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{int{\emph{ createNumber() \{ \newline int x = 42; // lives on the stack \newline return \&x; // return its address \newline \} // x is destroyed here \newline \newline int main() \{ \newline int}} p = createNumber(); \newline *p; // ❌ dangling — x is gone, memory no longer belongs to you \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{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.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Address of Operator}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{int x = 42; \newline int* ptr = \&x; // ptr holds the memory address of x} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Definition of a Caller}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{int add(int a, int b) \{ // callee \newline return a + b; \newline \} \newline \newline int main() \{ // caller \newline add(1, 2); \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Caller — the function that calls another function.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Passing Functions (Callbacks)}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#include \textless{}iostream\textgreater{} \newline \newline void sayHello() \newline \{ \newline std::cout \textless{}\textless{} "Hello!" \textless{}\textless{} std::endl; \newline \} \newline \newline void execute(void (*callback)()) \newline \{ \newline callback(); \newline \} \newline \newline int main() \newline \{ \newline execute(\&sayHello); // pass the function, not call it \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{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"} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{namespace alias}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{namespace short\_name = some::long::namespace; \newline \newline // Instead of: \newline some::long::namespace::type myVar; \newline \newline // You can write: \newline short\_name::type myVar;} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Creates a shorthand alias for a long namespace to make code less verbose. \newline \newline The alias can be used anywhere in the file in place of the full namespace name. \newline \newline Commonly used for long standard library namespaces like std::filesystem.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{const placed after a member function}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{class Object \{ \newline int m\_value = 10; \newline \newline public: \newline int getValue() const \{ return m\_value; \} // const: can only read \newline void setValue(int v) \{ m\_value = v; \} // non-const: can modify \newline \};} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{A const placed after a method signature means the function is read-only — it cannot modify any {\bf{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.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Default parameter values}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{// In C++, function parameters can be given default values, meaning the caller does not need to provide them \newline // explicitly. Default parameters must appear at the end of the parameter list, so no non-defaulted parameter \newline // can follow a defaulted one. If the caller omits a defaulted argument, the default value is used \newline // automatically; otherwise the caller's value takes precedence. \newline \newline void foo(int a, int b, int c = 10); // c defaults to 10 \newline void bar(int a, int b = 5, int c = 10); // b defaults to 5, c to 10 \newline // void baz(int a = 1, int b, int c); // ERROR: non-default after default \newline \newline // Valid calls: \newline foo(1, 2); // c = 10 \newline foo(1, 2, 3); // c = 3 \newline \newline bar(1); // b = 5, c = 10 \newline bar(1, 2); // b = 2, c = 10 \newline bar(1, 2, 3); // b = 2, c = 3} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{static\_cast}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{targetType result = static\_cast\textless{}targetType\textgreater{}(sourceValue);} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{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.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Direct versus copy initialization of a constructor}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{T b(a); // direct initialization \newline T b = a; // copy initialization} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{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.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Access Modifiers}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{class my\_class \{ \newline public: \newline int public\_variable; // accessible from anywhere \newline void public\_function(); // accessible from anywhere \newline \newline protected: \newline int protected\_variable; // accessible by this class and children \newline void protected\_function(); // accessible by this class and children \newline \newline private: \newline int private\_variable; // only accessible within this class \newline void private\_function(); // only accessible within this class \newline \};} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Controls who can access members (variables and functions) of a class. \newline \newline public — accessible from anywhere. \newline \newline protected — accessible only within the class and any class that inherits from it. \newline \newline private — accessible only within the class itself, not even by children.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{constexpr}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{constexpr int max\_size = 100; // evaluated at compile time \newline constexpr const char* my\_string = "hello"; // evaluated at compile time \newline \newline const int runtime\_size = get\_size(); // OK — const can be runtime \newline constexpr int bad = get\_size(); // error — constexpr must be compile time} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Declares that a value is constant and must be known at compile time. \newline \newline Stronger than const — the compiler evaluates it before the program runs. \newline \newline Allows the compiler to make deeper optimisations than const alone.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{override}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{class parent\_class \{ \newline public: \newline virtual void my\_function() \{ \} \newline \}; \newline \newline class child\_class : public parent\_class \{ \newline public: \newline void my\_function() override \{ \} // compiler confirms this matches parent \newline void my\_functon() override \{ \} // compiler error — typo caught \newline void my\_functon() \{ \} // no error — silently creates new function \newline \};} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Tells the compiler you are intentionally overriding a virtual function from a parent class. \newline \newline If the function signature doesn't match the parent's virtual function exactly, the compiler will error. \newline \newline Without it, a typo or signature mismatch would silently create a new function instead of overriding the parent's.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Integer Literal Suffixes}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{1u // unsigned int \newline 1l // long \newline 1ul // unsigned long \newline 1ll // long long \newline 1ull // unsigned long long} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Suffixes added to integer literals to specify their type explicitly. \newline \newline Used to avoid signed/unsigned mismatch warnings when comparing with typed values. \newline \newline Common suffixes are u for unsigned, l for long, and ul for unsigned long.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Defnition of a Thread}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#include \textless{}thread\textgreater{} \newline \#include \textless{}iostream\textgreater{} \newline \newline void doWork() \{ \newline std::cout \textless{}\textless{} "thread running\textbackslash{}n"; \newline \} \newline \newline int main() \{ \newline std::thread t(doWork); // thread starts here \newline t.join(); // main waits for it to finish \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{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.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{L values (Left Values)}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{int x = 10; // x is an lvalue \newline x = 20; // valid: lvalue on the left of = \newline \newline int y = x + 1; // (x + 1) is an rvalue — temporary, no fixed address \newline int z = 42; // 42 is an rvalue literal \newline // \&(x + 1); // ERROR: cannot take address of an rvalue} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{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.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Definition of a Static Method}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{class MathHelper \{ \newline public: \newline static int add(int a, int b) \{ \newline return a + b; \newline \} \newline \}; \newline \newline int result = MathHelper::add(3, 5); // 8} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{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.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Definition of a Signature}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#include \textless{}iostream\textgreater{} \newline \newline void greet(std::string name) \{ // signature: greet(std::string) \newline std::cout \textless{}\textless{} "Hello, " \textless{}\textless{} name \textless{}\textless{} "!\textbackslash{}n"; \newline \} \newline \newline int main() \{ \newline greet("Alice"); // → Hello, Alice! \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{A function signature in C++ is the part of a function declaration that identifies it uniquely to the compiler. It consists of: \newline \newline Function name \newline Parameter types (number, order, and types)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Reference declaration (in type declarations)}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{int x = 42; \newline int\& ref = x; // ref IS x — same memory location \newline \newline ref = 100; // x is now 100} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Endless For-Loop}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{for (;;)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Macros}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{// Creation \newline \#define OPERATION(input) input {\emph{ multiplier \newline \newline // Usage \newline int result = OPERATION(value); // expands to: int result = value }} multiplier;} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{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.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Passing This to Other Objects}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#include \textless{}iostream\textgreater{} \newline \newline class B \{ \newline public: \newline void hello(class A{\emph{ a); \newline \}; \newline \newline class A \{ \newline public: \newline int number = 42; \newline \newline void send() \{ \newline B b; \newline b.hello(this); // passing this to B \newline \} \newline \}; \newline \newline void B::hello(A}} a) \{ \newline std::cout \textless{}\textless{} a-\textgreater{}number \textless{}\textless{} "\textbackslash{}n"; // prints 42 \newline \} \newline \newline int main() \{ \newline A a; \newline a.send(); \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{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.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{The Two Main Ways of Initializing a Function}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{// 1. Default then assign \newline std::thread t; \newline t = std::thread(foo); \newline \newline // 2. Declare and initialise in one line \newline std::thread t(foo);} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{bitwise OR assignment operator}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{|= \newline \newline // Example \newline \newline bool result = false; // 0 \newline result |= false; // 0 | 0 = 0 \newline result |= false; // 0 | 0 = 0 \newline result |= true; // 0 | 1 = 1 \newline result |= false; // 1 | 0 = 1 — stays true \newline result |= false; // 1 | 0 = 1 — stays true \newline // result is true} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{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.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Operator=}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{T\& operator=(const T\& other) \{ \newline return *this; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{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.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{For Loop with Internal Cursor}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{// reading lines from a file \newline for (std::string line; \seqsplit{std::getline(file\_stream}, line);) \{ \newline // process line \newline \} \newline \newline // reading words from a file \newline for (std::string word; file\_stream \textgreater{}\textgreater{} word;) \{ \newline // process word \newline \} \newline \newline // reading integers from a file \newline for (int number; file\_stream \textgreater{}\textgreater{} number;) \{ \newline // process number \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Used when the object being read maintains its own internal cursor that advances automatically with each read. \newline \newline The condition of the for loop both reads the next item AND advances the cursor in one step, so no increment is needed. \newline \newline Only works with stream objects like std::ifstream, std::cin etc. that consume data sequentially.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Global Namespace ::}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{::testing::Test // explicitly uses global testing::Test \newline testing::Test // uses testing::Test from current namespace first \newline \newline ::std::string // explicitly global std::string \newline std::string // std::string from current namespace first} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{A leading :: tells the compiler to start looking from the global namespace rather than the current one. \newline \newline Used to avoid ambiguity when a name might exist in both the current namespace and the global namespace. \newline \newline Without it the compiler searches the current namespace first, which could resolve to the wrong type.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{const}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{const int max\_size = 100; // cannot be changed \newline const char* my\_string = "hello"; // string cannot be modified \newline max\_size = 200; // error — cannot modify const} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Declares that a variable's value cannot be modified after initialisation. \newline \newline Can be applied to variables, pointers, and function parameters. \newline \newline Enforced at runtime.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{char*}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{const char* my\_string = "hello"; \newline // h e l l o \textbackslash{}0 \newline // {[}0{]}{[}1{]}{[}2{]}{[}3{]}{[}4{]}{[}5{]} \newline \newline my\_string + 1; // points to {[}1{]}, reads "ello" \newline my\_string + 2; // points to {[}2{]}, reads "llo"} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{A pointer to a character, typically used to point to the start of a string. \newline \newline Strings in C are just arrays of characters ending with a null terminator \textbackslash{}0 — reading a string means reading every character from the pointer until \textbackslash{}0 is reached. \newline \newline Adding a number to the pointer moves it forward by that many characters, changing where reading begins.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Inheritance}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{class child\_class : public parent\_class \{ \newline // child\_class now has access to all public members of parent\_class \newline \};} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Allows a class to inherit members and behaviour from a parent class using :. \newline \newline public inheritance means the parent's public members stay public in the child. \newline \newline private inheritance means the parent's public members become private in the child. \newline \newline Use :: before the parent class name to explicitly reference the global namespace.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Lambda Functions}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{[}\&\textless{}OBJECT\textgreater{}{]} \{ \newline \textless{}CODE\textgreater{}; \newline \textless{}CODE\textgreater{}; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{The brackets tell the lambda which variables from the surrounding scope it's allowed to use, and how it remembers them. \newline \newline 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.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Constructing an obect in C++}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{TypeName \seqsplit{variableName(constructorArguments);}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{This is how it would look in Python: \newline variable\_name = \seqsplit{ClassName(constructor\_arguments)}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Dereferencing a Pointer}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{int x = 42; \newline int{\emph{ p = \&x; // p holds the address of x \newline \newline }}p; // dereference — follow the pointer to get 42} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{The * in front of a pointer means "go to the address this pointer holds and give me what's there."} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Range Based For-Loops}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{for (const \textless{}type\textgreater{}\& \textless{}element\textgreater{} : \textless{}collection\textgreater{}) \{ \newline // use \textless{}element\textgreater{} \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{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. \newline \newline {\bf{const}} — omit if you need to modify \textless{}element\textgreater{} \newline {\bf{\&}} — omit if you want a copy of each element rather than a reference} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Template Functions}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{template \textless{}typename T\textgreater{} \newline T add(T a, T b) \{ \newline return a + b; // T must support the + operator \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Try Catch}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{try \{ \newline // code that might throw an exception \newline \} catch (const std::exception\& e) \{ \newline // handle exception \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{catch(...). This is for any unkown exception that can't be caught by an std::exception.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Template Aliases}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{// The template \newline template \textless{}typename T\textgreater{} \newline class Box \{ \newline T contents; \newline \}; \newline \newline // Without an alias — verbose \newline Box\textless{}int\textgreater{} myBox; \newline \newline // The alias \newline using IntBox = Box\textless{}int\textgreater{}; \newline \newline // With the alias — cleaner, same thing \newline IntBox myBox;} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Factory Method}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{class MyClass \{ \newline public: \newline static MyClass fromInput(std::string input) \{ \newline MyClass object; \newline object.m\_value = std::stoi(input); \newline return object; \newline \} \newline private: \newline int m\_value; \newline \}; \newline \newline MyClass result = \seqsplit{MyClass::fromInput(input);}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{A static method that constructs and returns an object, hiding the construction details from the caller.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{=delete}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{class T \{ \newline T(const T\&) = delete; // copying forbidden \newline \}; \newline \newline T a; \newline T b(a); // compiler error} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{= 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.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{constexpr}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{constexpr \textless{}datatype\textgreater{} variableName = \textless{}value\textgreater{};% Row Count 1 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{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.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Member Initializer List}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{class Car \{ \newline std::string m\_brand; \newline int m\_year; \newline \newline public: \newline Car(std::string brand, int year) \newline : m\_brand(brand) // initialize m\_brand with brand \newline , m\_year(year) // initialize m\_year with year \newline \{\} \newline \};} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{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. \newline \newline {\bf{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".} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{static}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{static variableName = \textless{}value\textgreater{};} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Signals that a value belongs to the class, not any instance, and is fixed at compile time.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Definition of a Non-Static Member Function}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{class Dog \{ \newline public: \newline std::string name; \newline \newline void bark() \{ \newline std::cout \textless{}\textless{} name \textless{}\textless{} " says woof!\textbackslash{}n"; \newline \} \newline \}; \newline \newline int main() \{ \newline Dog d; \newline d.name = "Rex"; \newline \newline d.bark(); // prints "Rex says woof!" \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{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.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Commenting Out Unused Parameters in C++}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{// You must accept both parameters to match the signature \newline void process(int /{\emph{unused}}/, int used) \newline \{ \newline std::cout \textless{}\textless{} used; // unused not needed, but must be in signature \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{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.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{\seqsplit{R"delimiter(...)delimiter"}}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{// Regular string — special characters need escaping \newline const char{\emph{ regular = "line1\textbackslash{}nline2\textbackslash{}t\textbackslash{}"quoted\textbackslash{}""; \newline \newline // Raw string — no escaping needed, written exactly as it should appear \newline const char}} raw = R"delimiter( \newline line1 \newline line2 \newline "quoted" \newline \$variable \newline )delimiter";} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Used when a string contains special characters like \$, ", \textbackslash{}, or newlines that would need escaping in a regular string. \newline \newline Everything between the delimiters is treated as literal text — no escape sequences are processed. \newline \newline 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).} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Virtual Function}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{class parent\_class \{ \newline public: \newline virtual void my\_function() \{ \newline // base implementation \newline \} \newline \}; \newline \newline class child\_class : public parent\_class \{ \newline public: \newline void my\_function() override \{ \newline // child's own implementation, replaces parent's \newline \} \newline \};} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{A function in a base class that is designed to be overridden by child classes. \newline \newline The override keyword confirms to the compiler that you are intentionally overriding a parent function. \newline \newline Without virtual in the parent, the child's version would not be called polymorphically.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{std::function}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{std::function\textless{}return\_type(argument\_type)\textgreater{} my\_function; \newline \newline // storing a regular function \newline std::function\textless{}int(int, int)\textgreater{} add = {[}{]}(int a, int b) \{ return a + b; \}; \newline \newline // storing a lambda \newline std::function\textless{}void(std::string)\textgreater{} printer = {[}{]}(std::string s) \{ \newline std::cout \textless{}\textless{} s; \newline \}; \newline \newline // calling it \newline add(2, 3); // returns 5 \newline printer("hello"); // prints "hello"} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{A general purpose wrapper that can hold any callable — a function, lambda, or function object. \newline \newline The template parameter describes the function signature: return type and argument types. \newline \newline Useful for storing and passing functions as variables.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}