C++ Beginner's Guide

    Introduction

    What Is This Guide? About

    • an organized collection of links to topic articles
    • about learning modern, idiomatic C++
    • (roughly) ordered by increasing level of C++ proficiency (top to bottom)
    • many articles are based on slide decks taken from an undergraduate C++ crash course

    Required Knowledge

    You should know how to use a command line and should have a basic understanding of fundamental imperative programming concepts, like

    • variables   (int i = 0, var x = 0, … )
    • conditional branching   (if, then, else, … )
    • loops   (for, while, repeat, … )
    • functions / subroutines   (int main(), fn main, … )

    It certainly helps if you are already somewhat familiar with other programming languages like Python or Java. You should be aware however, that C++ is very different from Java or C# despite the superficial syntactic similarities.

    What is C++?

    • multi-paradigm: value-oriented, procedural, generic, functional, object-oriented
    • value semantics by default
    • custom types can behave exactly like built-in types
    • deterministic object lifetime
    • precise memory control down to individual bits
    C++98 1998 the original standard
    C++11 2011 almost a new language modern C++
    C++14 2014 some improvements
    C++17 2017 new features & library extensions
    C++20 2020 game-changing new features & libraries

    C++ vs. …

    C++ C
    not a strict subset of C++
    stronger type system weak type system
    high-level abstractions only low-level memory abstraction
    typed compile-time programming only untyped macros for compile-time programming
    powerful custom types (classes) only data aggregation (struct)
    use compiler as correctness checker get the code to compile quickly
    if it compiles, it should be correct debugging is the real work

    C++ Java
    multi-paradigm: value-oriented, procedural, generic, functional, object-oriented mainly object-oriented, some functional and generic aspects
    value semantics by default for fundamental & custom types value semantics only for primitives (int, float,… )
    optional reference semantics for all types baked-in reference semantics for class types
    precise control over memory (de-)allocation; no garbage collection garbage collector; can degrade performance
    deterministic & controllable object lifetime no predictable object lifetime control
    ⇒ memory frugal ⇒ high memory consumption
    aggressive inlining can eliminate slow function calls performance degradation due to un-devirtualizable, non-inlinable methods

    C++ Python
    almost always faster almost always slower (in practice around 25-50 times)
    complex syntax and tons of features can be intimidating to newcomers simple syntax; usually easy to comprehend
    statically typed dynamically typed
    many types of bugs can be caught at compile time many types of bugs will only manifest at runtime
    suited for safety-critical large-scale systems hard to build reliable large-scale systems
    even simple, small-scope tasks can quickly require an expert knowledge of various arcane corner cases & quirks tends to be more beginner-friendly and small scripts are usually quickly written
    fairly small standard library but extensive ecosystem with libraries for nearly everything batteries included philosophy with tons of libraries only one import away

    C++ – When & Where?

    • if memory consumption is critical
    • if runtime is critical
    • if energy consumption is critical
    • OS level programming
    • embedded systems
    • large-scale, massively parallel systems
    • source-code portability across architectures
    • "scripting" & rapid prototyping
    • GUIs with trivial internal logic

    Learning Resources

    Chapters

    First Steps

    Input & Output

    Custom Types – Part 1

    Diagnostics

    Standard Library – Part 1

    Function Objects

    Standard Library – Part 2

    Code Organization


    Separate Compilation In One Image (click to enlarge)
    example of compiling two source files separately and linking the resulting object files into an executable

    Custom Types – Part 2

    Generic Programming

    Memory Management

    Software Design Basics