C++ Reference
|
This section documents C++23 (ISO/IEC 14882:2024), as published by ISO/IEC JTC1/SC22/WG21 (wg21), verified against the freely available working draft N5046 (eel.is/c++draft) and cppreference.com. This content was generated with the assistance of AI and should be verified against the working draft and cppreference.com before being relied on in production. This section’s bibliography lists the reference material consulted while preparing these pages. |
Welcome to the C++ reference. C++ is a general-purpose, statically-typed, compiled language standardized by ISO/IEC JTC1/SC22 Working Group 21 (WG21) — direct control over memory and layout, plus zero-overhead abstractions (classes, templates, RAII) that cost nothing at run time compared to hand-written C. This section targets C++23 (ISO/IEC 14882:2024), flagging C++20/23-only features against their C++17 fallback wherever this environment’s own toolchain made that concrete.
If you are new here, read Getting Started and Program Structure and Compilation first, then the Language fundamentals pages in order — from there, the remaining groups (object-oriented programming, generic/compile-time programming, the standard library, error handling, concurrency, and design/performance/tooling) can be read in any order as you need them.
C and C++
C++ began in 1979 as "C with Classes" and still shares C’s declaration syntax, its arithmetic types, its
pointer model, and most of its standard library (reachable through the <cXXX> headers — <cstdio>,
<cstring>, <cmath>). If you already know C, most of this section will read as familiar syntax with
substantially different idioms layered on top: RAII instead of manual malloc/free pairs, templates and
concepts instead of _Generic and macros, std::string/std::vector instead of raw buffers and lengths,
exceptions or std::expected instead of sentinel return values and errno.
C++ is not a strict superset of C, and the gap has widened rather than closed — the two are standardized
by different committees (WG21 for C++, WG14 for C) that coordinate but do not merge. Valid C that is not
valid C++ includes the implicit void * conversion (int *p = malloc(n); compiles in C, and needs a cast in
C++), variable-length arrays, restrict, tentative definitions, and C99’s fuller form of designated
initializers (C++20 accepts only the in-declaration-order subset). Meanwhile C23 has adopted several
C++ spellings outright — bool/true/false as keywords, nullptr, static_assert, thread_local,
[[attributes]], binary literals and ' digit separators, plus constexpr (for objects only, not functions)
and auto type inference. Calling C from C++ is routine and goes through
extern "C", which suppresses C++ name mangling; see
Program Structure and Compilation.
The C Reference on this site documents C23 in its own right. These pages line up roughly as follows, for reading one against the other:
| C page | C++ page | What changes |
|---|---|---|
Same compilers, different |
||
C++ adds name mangling, |
||
Shared arithmetic model; C++ adds |
||
C++ adds overloading, |
||
C++ adds overloading, default arguments, lambdas, and |
||
A C++ |
||
Raw pointers still exist; ownership moves to |
||
|
||
|
||
|
||
The same preprocessor, but far less of the work falls to it. |
||
Return codes and |
||
|
||
One shared memory model; C++ adds RAII locks, |
||
Two separate release trains, deliberately kept close but never identical. |
What’s Covered
Getting started
-
Getting Started — what C++ is, the standard editions, compilers, "Hello, World" with
std::println, and compiling with-std=c++23 -Wall -Wextra. -
Program Structure and Compilation — translation units, the One Definition Rule, headers, linkage,
main, modules, and static vs. dynamic libraries.
Language fundamentals
-
Lexical Structure and Style — tokens, identifiers, literals, comments, attributes, and naming conventions.
-
Basic Types and Values — fundamental and fixed-width types,
auto/decltype, type aliases, and conversions. -
Constants, Enumerations, and Initialization —
const/constexpr/consteval/constinit,enum class, and brace initialization. -
Operators and Expressions — precedence, value categories,
<⇒, and safe integer comparison. -
Control Flow —
if/switchwith init,if constexpr/if consteval, loops, and structured bindings. -
Functions and Lambdas — overloading, defaulted/deleted functions, lambdas,
std::function, andnoexcept. -
Strings and Text —
std::string/string_view,<charconv>,std::format/std::print, and<regex>. -
Numbers and Math — floating-point pitfalls,
<cmath>,<random>, and<bit>.
Object-oriented programming
-
Classes and Objects — constructors, special member functions, and the rule of zero/three/five.
-
Inheritance and Polymorphism — virtual functions, abstract classes, object slicing, and the casts.
-
Operator Overloading and Conversions —
operator<⇒,operator[], and conversion operators. -
Move Semantics and Value Categories — rvalue references,
std::move/std::forward, and copy elision. -
Memory Management and Smart Pointers — RAII,
unique_ptr/shared_ptr/weak_ptr, and allocators.
Generic and compile-time programming
-
Templates — function/class templates, CTAD, variadic templates, and specialization.
-
Concepts and Constraints —
concept,requires, and subsumption. -
Compile-Time Programming —
static_assert,<type_traits>, and constexpr virtual functions. -
Namespaces, Modules, and the Preprocessor — namespaces, ADL, the preprocessor, and feature-test macros.
Standard library
-
Standard Library Overview — how the library is organized, and freestanding vs. hosted.
-
Containers — sequence/associative/unordered containers,
flat_map, andstd::span/std::mdspan. -
Iterators and Algorithms — iterator categories,
<algorithm>/<numeric>, andstd::erase_if. -
Ranges and Views —
std::ranges, views, and range adaptors. -
Vocabulary Types —
optional,variant,any, andexpected. -
Dates, Times, and Chrono — durations, clocks, calendars, and time zones.
-
Input, Output, and Streams — the iostreams hierarchy, manipulators, and string/span streams.
-
Filesystem —
std::filesystem::pathand file operations.
Error handling and robustness
-
Error Handling — exceptions,
noexcept,error_code,std::expected, and<stacktrace>.
Concurrency
-
Threads and Synchronization —
std::thread/jthread, mutexes, and condition variables. -
Async, Futures, and Atomics —
std::async,std::atomic, and parallel algorithms. -
Coroutines —
co_await/co_yield/co_returnandstd::generator.
Design, performance, and tooling
-
Patterns and Idioms — RAII, Pimpl, NVI, CRTP, and type erasure.
-
Performance — the zero-overhead principle, profiling, and sanitizers.
-
Build and Tooling — CMake, package managers, and static analysis.
-
Testing — GoogleTest, Catch2, Boost.Test, and CTest.
-
C++ Standards and C++26 — every edition’s headline features, and what’s coming next.
Reference
-
Cheat Sheet (PDF) — a single-page, printable summary of everything in this section, with a downloadable PDF.
Bibliography
-
The Standard C++ Foundation — "The Standard" and its C++23/C++26 status pages — the authoritative overview of what each edition contains and where the next one stands in the ISO process.
-
WG21 — the ISO C++ standards committee, publisher of the working drafts every page in this section is checked against, including the N5046 working draft and its continuously updated mirror at eel.is/c++draft.
-
cppreference.com — the primary source this section’s syntax and standard library coverage is verified against, including its C++20, C++23, and C++26 feature pages.
-
The C++ Core Guidelines — the source for this section’s naming/formatting conventions and several of its Patterns and Idioms recommendations.
-
GCC documentation and its C++ standards support status, Clang documentation and its C++ standards support status, and MSVC documentation — the three compiler toolchains this section’s compiler/flag/tooling coverage refers to throughout.
-
CMake documentation, vcpkg documentation, and Conan documentation — the primary sources for Build and Tooling.
-
GoogleTest documentation, Catch2 documentation, and Boost.Test documentation — the primary sources for Testing.
-
Stroustrup, Bjarne. A Tour of C++, 3rd ed. Addison-Wesley Professional, 2022. ISBN 9780136816485. Consulted reference, cross-checked against its public table of contents and excerpts only — see the author’s book page and its publisher listing.
-
Bancila, Marius. Modern C++ Programming Cookbook, 3rd ed. Packt Publishing, 2024. ISBN 9781835080108. Consulted reference, cross-checked against its public table of contents only — see its publisher listing.
Both books above are consulted references, not the primary source for this section; on any discrepancy, or wherever either is silent on a feature introduced after it was written, the working draft and cppreference.com win.