Access Control
Access control (public, private, protected) enables encapsulation by controlling which code can access class members.
Access control (public, private, protected) enables encapsulation by controlling which code can access class members.
Initialize arrays and simple structs using brace-enclosed lists without constructors. Concise syntax for multiple members.
Alignment ensures data is placed at memory addresses divisible by its size, improving CPU access speed. Padding fills gaps to maintain alignment.
Allocators are objects that manage memory allocation for STL containers. They provide a standardized interface for customizing how containers acquire and release memory.
Brief introduction to the topic...
The assembler converts human-readable assembly code into binary machine code (object files). Each assembly instruction becomes actual CPU instructions.
auto lets the compiler deduce variable types from initializers, reducing verbosity and improving maintainability.
Brief introduction to the topic...
Build systems automate compilation, dependency management, and linking. They track changes and rebuild only what's necessary, making large C++ projects manageable.
What are Build Types?
C++ syntax defines how code is written and structured. Understanding basic syntax is essential for writing valid C++ programs.
The C++ compilation process transforms source code into executable binary through four main stages: preprocessing, compilation, assembly, and linking.
The C++ ecosystem encompasses compilers, build systems, package managers, IDEs, libraries, and testing frameworks. Understanding this landscape is crucial for effective C++ development.
Calling conventions define how functions receive parameters and return values at the assembly level - register usage, stack cleanup, and parameter passing order.
The chrono library provides type-safe time utilities for durations, time points, and clocks. It's designed to prevent common time-related bugs through strong typing.
Understanding how classes are laid out in memory is essential for optimization, debugging, and interfacing with other languages.
Class templates create generic classes that work with different types. Think std::unique_ptr - same class, different types.
What are Variables?
File Anatomy
The compilation phase translates preprocessed C++ code into assembly language. This is where syntax checking, semantic analysis, optimization, and code generation happen.
Concepts are named requirements for template arguments that replace SFINAE with readable constraints. Requires expressions are the building blocks that check if code compiles at compile-time.
Brief introduction to the topic...
CV-qualifiers (const and volatile) modify type behavior. const prevents modification; volatile prevents compiler optimization.
const with pointers creates three distinct scenarios. Understanding the difference prevents bugs and documents intent.
constexpr indicates values or functions can be evaluated at compile-time, enabling compile-time computation and optimization.
Constructors initialize objects and allocate resources. Destructors clean up when objects are destroyed. Together they enable RAII (Resource Acquisition Is Initialization).
Copy creates a duplicate of an object. Move transfers ownership of resources from one object to another. Understanding when each happens is crucial for performance and correctness.
Cross-compilation builds executables for a different platform (target) than the one running the compiler (host). Essential for embedded systems, mobile development, and deploying to different architectures.
Extend smart pointers to manage any resource requiring special cleanup beyond delete. Enable RAII for files, handles, connections, locks - anything needing cleanup.
decltype deduces the type of an expression, preserving references and const qualifiers exactly.
decltype(auto) (C++14) combines auto convenience with decltype precision - deduces type while preserving references and const.
Object created without explicit initializer. Behavior depends on type and storage duration. Dangerous for fundamental types in local scope.
C++ evolves through standardized versions released approximately every three years. Each standard adds features, fixes issues, and modernizes the language while maintaining backward compatibility.
C++ supports two forms of polymorphism: dynamic (runtime, using virtual functions) and static (compile-time, using templates). Each has different trade-offs.
Core Commands
Creating Executables
Expressions produce values; statements perform actions. Understanding the distinction is fundamental to C++ programming.
What is ExternalProject?
What is FetchContent?
The filesystem library (C++17) provides portable facilities for manipulating files and directories. It replaces platform-specific APIs and C-style file operations with a modern, type-safe interface.
What is find_package()?
Fold expressions provide a concise way to apply operators to variadic template parameter packs. They eliminate the need for recursive template patterns.
Full specialization provides a completely custom implementation for specific template arguments. It's like saying "for this exact type, use this completely different code."
Function overloading allows multiple functions with the same name but different parameters. The compiler selects the best match based on arguments.
Function templates let you write one function that works with different types. The compiler generates specific versions for each type you use.
C++ provides built-in fundamental types for integers, floating-point numbers, characters, and booleans.
C++11 refined value categories into five types: lvalue, prvalue, xvalue, glvalue, and rvalue. Understanding these enables perfect forwarding and move semantics.
Brief introduction to the topic...
Headers (.h, .hpp) contain declarations that are shared across multiple source files. The #include directive copies header contents into source files during preprocessing.
pragma once
Inheritance lets you create new classes based on existing ones, reusing code and establishing "is-a" relationships. Derived classes inherit members from base classes and can add new functionality or override existing behavior.
inline suggests the compiler replace function calls with function body, eliminating call overhead. Modern compilers decide automatically.
The iostream library provides facilities for input/output operations through streams. It's a type-safe, extensible alternative to C's printf/scanf.
Installation Methods
Iterators are the glue between containers and algorithms. They provide a uniform interface for traversing and accessing elements in different container types, enabling generic algorithms.
Tokens are the smallest units of a C++ program. Keywords are reserved words with special meaning that cannot be used as identifiers.
Lambdas (C++11) are anonymous functions that can capture variables from surrounding scope, enabling functional programming patterns and convenient callbacks.
Types of Libraries
Understanding Library Linking
The linker combines multiple object files and libraries into a single executable, resolving symbol references and assigning final memory addresses.
Brief introduction to the topic...
Brief introduction to the topic...
Every C++ expression has a type and a value category. Lvalues have persistent storage; rvalues are temporaries.
Makefiles define rules for building projects using the Make build system. They specify dependencies and commands to compile source code incrementally.
Data arranged at addresses that are multiples of its size. Required for correctness on some architectures, critical for performance on all.
Understanding how C++ programs use memory is fundamental to writing efficient, safe code. Memory is divided into distinct regions with different characteristics and management strategies.
Multiple inheritance allows a class to inherit from multiple base classes. This enables combining functionality but introduces complexity, especially the diamond problem.
Name mangling (name decoration) encodes C++ function signatures into unique symbol names for the linker. This enables function overloading and namespaces while maintaining linkage compatibility.
Manual dynamic memory management in C++. Allocates on heap, requires explicit deallocation. Modern C++ prefers smart pointers.
noexcept specifies that a function won't throw exceptions, enabling optimizations and stronger guarantees.
Object files (.o, .obj) are compiled but not yet linked binary files containing machine code, data, and metadata for the linker.
Object lifetime spans from construction to destruction. Understanding lifetime is critical for memory safety, RAII, and avoiding undefined behavior.
Object slicing occurs when you copy a derived class object to a base class object. The derived parts are "sliced off" and lost.
Brief introduction to the topic...
Brief introduction to the topic...
A comprehensive, user-friendly guide to CMake organized for easy reference and learning.
Partial specialization lets you specialize templates for a pattern of types, not just one specific type. It's like "for all pointer types" or "for all pairs of same types."
Constructs objects in pre-allocated memory without allocating. Separates construction from allocation for custom memory management.
Pointer arithmetic navigates contiguous memory with automatic scaling by type size. Essential for arrays but dangerous without bounds checking.
The preprocessor is a text manipulation tool that runs before compilation. It handles #include, #define, #ifdef, and other directives, producing pure C++ code for the compiler.
C++ programs consist of one or more source files containing declarations, definitions, and the required main() function.
RAII is a fundamental C++ idiom where resource lifetime is tied to object lifetime. Resources are acquired in constructors and released in destructors, ensuring automatic cleanup and exception safety.
Ranges (C++20) is a modern library that provides composable, lazy-evaluated operations on sequences. It replaces traditional iterator pairs with range objects and introduces views for efficient data transformation pipelines.
A pointer is a variable that stores a memory address, allowing indirect access to other variables.
When template type deduction creates "reference to reference", C++ applies collapsing rules. This enables perfect forwarding.
A reference is an alias - another name for an existing object. Unlike pointers, references cannot be null, must be initialized, and cannot be reseated.
These rules tell you which special member functions to define based on your class's resource management needs.
SFINAE (Substitution Failure Is Not An Error) is a fundamental C++ template mechanism that enables conditional template compilation. std::enable_if is the primary tool for applying SFINAE in practice.
Integer types can be signed (negative and positive) or unsigned (only positive). Understanding signedness prevents bugs and overflow issues.
Linking can be static (library code copied into executable) or dynamic (library loaded at runtime). Each has trade-offs in size, deployment, and performance.
Smart pointer with shared ownership via reference counting. Multiple shared_ptrs can own the same object, deleted when last owner destroyed.
Smart pointer with exclusive ownership. Zero overhead, automatic cleanup, move-only semantics. The default choice for dynamic memory.
Non-owning observer of shared_ptr-managed objects. Doesn't increase reference count, enables checking if object still exists.
STL algorithms are generic functions that work with any container through iterators. They provide tested, optimized implementations of common operations. Never write your own sort or search - use the STL!
Containers store collections of objects. The STL provides optimized, well-tested containers for different access patterns and performance needs. Choose the right container for your use case.
Storage duration defines when and where objects are created and destroyed. C++ has four storage durations: automatic, static, dynamic, and thread.
Pointers of different types cannot point to the same memory (with exceptions). Enables compiler optimizations but causes undefined behavior when violated.
C++ provides std::string_view (C++17) for non-owning string references. Rich API for searching, modifying, and converting text data.
Understanding Target Properties
Template argument deduction lets the compiler figure out template parameters from function arguments automatically. No need to write func(5) when func(5) works!
A translation unit is a single source file plus all its included headers after preprocessing. It's the basic unit of compilation in C++.
C++ performs automatic (implicit) and manual (explicit) type conversions. Understanding these prevents bugs and data loss.
Type traits are compile-time tools that query and transform types. They power template metaprogramming and SFINAE, letting you write code that adapts to different types automatically.
C++11 brace initialization {} - one syntax for all types. Consistent, safe (prevents narrowing), solves gotchas.
The utilities library provides general-purpose components that don't fit into other categories but are essential for modern C++ development.
Explicitly request zero-initialization for fundamentals, default construction for classes. Safer than default initialization.
Variadic templates accept any number of arguments of any types. They're the foundation for functions like std::make_tuple, printf, and perfect forwarding.
Virtual functions enable runtime polymorphism through dynamic dispatch. Understanding how they work (vtables) helps you understand their cost and use them effectively.
C++ is a general-purpose, compiled programming language that extends C with object-oriented,
Overview
Project Structure