About C++ Crash Course

A fast-paced, thorough introduction to modern C++ written for experienced programmers. After reading C++ Crash Course, you’ll be proficient in the core language concepts, the C++ Standard Library, and the Boost Libraries.

C++ is one of the most widely used languages for real-world software. In the hands of a knowledgeable programmer, C++ can produce small, efficient, and readable code that any programmer would be proud of.

Designed for intermediate to advanced programmers, C++ Crash Course cuts through the weeds to get you straight to the core of C++17, the most modern revision of the ISO standard. Part 1 covers the core of the C++ language, where you’ll learn about everything from types and functions, to the object life cycle and expressions. Part 2 introduces you to the C++ Standard Library and Boost Libraries, where you’ll learn about all of the high-quality, fully-featured facilities available to you. You’ll cover special utility classes, data structures, and algorithms, and learn how to manipulate file systems and build high-performance programs that communicate over networks.

You’ll learn all the major features of modern C++, including:

  • Fundamental types, reference types, and user-defined types
  • The object lifecycle including storage duration, memory management, exceptions, call stacks, and the RAII paradigm
  • Compile-time polymorphism with templates and run-time polymorphism with virtual classes
  • Advanced expressions, statements, and functions
  • Smart pointers, data structures, dates and times, numerics, and probability/statistics facilities
  • Containers, iterators, strings, and algorithms
  • Streams and files, concurrency, networking, and application development

Downloading the Code

C++ Crash Course contains well over 500 code samples & nearly 100 exercises.

You can download all of them from Github.

You can clone the repository:

git clone git@github.com:JLospinoso/ccc

Or simply download the files using your browser:

So long as you have CMake, Boost, and git installed, you can then build all the examples with an out-of-source build:

cd ccc
git submodule init
git submodule update
mkdir build
cd build
cmake ..

Errata

To report an erratum, please submit an issue on Github https://github.com/JLospinoso/ccc/issues.
  • p. 353 fclose returns an int. If it's successful, fclose returns 0, otherwise EOF. (See https://en.cppreference.com/w/c/io/fclose)

Typos

  • p. xliv "and the function in the Jabberwock namespace" should read "and the function in the Func namespace"
  • p. 62 "Whether array_5 is initialized or not..." Should read "Whether array_4 is initialized or not..."
  • p. 76 In Listing 3-7, "*(lower + 4)" and "*(upper_ptr + 4)" should read "*(lower + 3)" and "*(upper_ptr + 3)", respectively.
  • p. 78 "Each Element also contains a prefix array (5) and an operating_number pointer (6)." Should read "... and an operating_number short."
  • p. 80 "Next, you initialize another int called new_value to 200 and assign it to original(3)."
  • p. 105 The Note should refer to Item 14, not Item 16 of Effective Modern C++ by Scott Meyers.
  • p. 128 The copy constructor in Listing 4-38 should use braced initializers for its member initializer, as in Listing 4-35.
  • p. 130 The Move Assignment checkmark is in the wrong place: typo p.130

  • p. 147 In Listing 5-14, "Bank(Logger* logger) : logger{ logger } ()" should read "Bank(Logger* logger) : logger{ logger } {}"
  • p. 175 "element-type(param-name&)[array-length]" should read "element-type(¶m-name)[array-length]"
  • p. 187 Listing 7-2 should throw a std::overflow_error at (4).
  • p. 188 "This argument is used to member initialize the private field value." Should read "This argument is used to member initialize the public field value."
  • p. 195 Table 7-6: The description for "a ^ b" should read "Bitwise XOR"
  • p. 203 Listing 7-14 Caption, "A refactor of Listing 7-13 using a static_cast..." should read "A refactor of Listing 7-13 using a reinterpret_cast...".
  • p. 239 To assign a label, prepend a statement with the desired name of the label followed by a colon.
  • p. 251 "..., you call va_list with the va_list structure" should read "..., you call va_end with the va_list structure"
  • p. 284 Figure 10-1, the direction of the arrows, SpeedUpdate, CarDetected, BrakeCommand, are reversed.
  • p. 289 "That’s all you have to do; assert will throw an exception if the initial speed is zero." should read "isn't zero."
  • p. 291 "Listing 10-9: A unit test encoding the requirement that the initial speed be zero" should read "that the initial sensitivity is five"
  • p. 304 "single-header" should read "single_header" (to correspond with the correct subdirectory within Catch).
  • p. 319 Listing 10-41: Caption should read "Using Boost Test" rather than "Using Google Test"
  • p. 327 Listing 10-50: "publish(A<BrakeCommand>)" should read "publish(A<BrakeCommand>())"
  • p. 328 Table 10-2: "A<type>)()" should read "A<type>()"; "An<type>)()" should read "An<type>()"
  • p. 351 "ownership to son_of_aragorn. Because son_of_aragorn can" should read "ownership to son_of_arathorn. Because son_of_arathorn can"
  • p. 368 Exercise 11-1: Should read "Reimplement Listing 11-13 to use a ..."
  • p. 382 Table 12-6, "Convenience function for constructing a tuple" should read "Convenience function for constructing a variant"
  • p. 385 Table 12-8, "Returns the month portion of the date" should read "Creates a period from d to d+n_days"
  • p. 404 Table 12-16, table header "Distribution" should read "Operation".
  • p. 404 The subtitle "A Partial List of Random Number Distributions" should read "A Partial List of Operations Available in <ratio>".
  • p. 431 "Constructs a priority_queue of Ts using ctr as its internal container and srt as its comparator object." should read "...and cmp as its comparator object."
  • p. 437 "when you give the key 8 (3)" should read "when you give the key 100 (3)"
  • p. 451 "Throws std::out_of_bounds" should read "Throws std::out_of_range"
  • p. 456 "You can remove subtrees from a ptree using the get_child method, ..." should read "You can get subtrees from a ptree using the get_child method, ..."

Introduction

p. xxxv: Companion Code

Foreword: An Overture to C Programmers

p. xxxix: C Constructs That Don't Work in C++

Chapter 1: Up and Running

p. 6: Wandbox

p. 6: Compiler Explorer

p. 6: Cling (Note: Not mentioned in the book, but a nice C++ REPL.)

p. 6: Visual Studio 2017 Community Edition Download

p. 10: GCC, the GNU Compiler Collection

p. 10: Clang: a C language family frontend for LLVM

p. 11: GCC mirror sites

p. 11: GnuPG

p. 12: Installing GCC: Configuration

p. 12: Installing GCC: Building

p. 12: Installing GCC: Testing

p. 12: Installing GCC

p. 12: The gcc-help mailing list archives

p. 23: Visual Studio Walkthrough: Debugging a Project (C++)

p. 25: About LLDB and Xcode

p. 25: GDB: The GNU Project Debugger

p. 25: The LLDB Debugger

p. 28: Debugging with GDB

p. 28: Stack Overflow

p. 28: CPP Subreddit

p. 28: CPP Slack

p. 29: CPPCast

p. 29: CPPReference

p. 29: CPlusPlus

p. 29: The "Draft" ISO C++ Standard (2017)

Chapter 2: Types

p. 35: The IEEE Standard for Floating-Point Arithmetic, IEEE 754.

p. 65: C++ Made Easier: Plain Old Data

Chapter 3: Reference Types

p. 86: Microsoft Security Bulletin MS01-033 - Critical (Code Red)

p. 87: C++ Core Guidelines

p. 87: East End Functions

p. 87: References

Chapter 6: Compile-time Polymorphism

p. 171: The Origin Library

Chapter 7: Expressions

p. 189: HeapAlloc

p. 189: malloc

p. 207: HSV Conversion

Chapter 10: Testing

p. 304-5, 309: Catch2

p. 310, 325, 328: Google Test/Google Mocks Documentation

p. 317: Boost Test

p. 333: HippoMocks

p. 337: FakeIt

p. 337: Trompeloeil

p. 339: Editor War

p. 339: Is TDD Dead?

Chapter 11: Smart Pointers

p. 349: Boost Smart Pointer

p. 363: Boost Intrusive

p. 387: Boost DateTime

Chapter 12: Utilities

p. 401-403: Boost Numeric Conversion

Chapter 13: Containers

p. 415: CPPReference

p. 415: CPlusPlus

p. 433: Boost Container

Chapter 15: Strings

p. 500: Boost Lexical Cast

p. 512, 515: Boost String Algorithms

Chapter 17: Filesystems

p. 551: Boost Filesystem

p. 571: The dir Command

p. 571: The ls Command

Chapter 18: Algorithms

p. 637: Boost Algorithm

p. 638: Boost Range

p. 638: Algorithmic Complexity

Chapter 19: Concurrency and Parallelism

p. 643: Integer Factorization

p. 655: Boost Lockfree

p. 662: C++ and The Perils of Double-Checked Locking

p. 662: Effective Concurrency: Know When to Use an Active Object Instead of a Mutex

Chapter 20: Network Programming with Boost Asio

p. 665: Boost Asio

p. 667: IANA Service Name and Transport Protocol Port Number Registry

p. 677: Boost Beast

p. 677: IETF RFCs

p. 677: Boost Beast example projects

p. 684: IANA Service Name and Transport Protocol Port Number Registry

p. 685: netcat

p. 689: nmap

Chapter 21: Applications

p. 704: Boost Program Options

p. 713: Boost Python