C++

A fast, compiled language that builds on C with classes, templates and a large standard library.

C++ extends C with classes, templates and a standard library of containers and algorithms. It is used where performance matters, such as game engines, browsers, trading systems and embedded software.

  • Advanced
  • 13 lessons
Not started yet
Start lesson 1

Lessons

  1. Hello, World!Write and run your first C++ program, and see how printing with cout differs from C's printf.
  2. Variables & TypesLearn C++'s basic types. Most everyday code uses int, double, string and bool.
  3. Control FlowLearn if/else, switch and loops in C++, including the range-based for loop for walking through collections.
  4. Functions & ReferencesLearn to write functions in C++, including default arguments, overloading and passing by reference.
  5. Classes & OOPLearn to define classes with constructors, member functions, inheritance and virtual methods.
  6. STL ContainersLearn the Standard Template Library's main containers and algorithms, so you can use ready-made vectors, maps and sets instead of writing your own.
  7. Error Handling & ExceptionsLearn to throw and catch exceptions in C++. Some projects, such as many game engines, turn them off, but you will meet them in most codebases.
  8. Mini Project: Bank Account SystemPut the earlier lessons together to build a small bank account system with classes, vectors, exceptions and file I/O.
  9. Pointers, References & MemoryLearn the three ways to refer to a value in C++ (by copy, by reference and by pointer) and what happens on the stack and the heap.
  10. RAII, Smart Pointers & Move SemanticsLearn RAII, smart pointers and move semantics: how C++ ties memory, files and locks to an object's lifetime so they are released automatically, even when an exception is thrown.
  11. Templates & Compile-Time GenericsLearn to write templates, which let the compiler generate a version of a function or class for each type you use, with no runtime cost.
  12. Modern C++: Lambdas, Algorithms & RangesLearn lambdas, the standard algorithms and ranges, which let you say what you want done instead of writing index loops by hand.
  13. C++ CheatsheetModern C++ (17/20) on one page — RAII, STL, smart pointers.

Install it on your own computer

C++ uses the same compilers as C. GCC, Clang, and MSVC all support C++. Use the g++ or clang++ commands instead of gcc/cc.

Bash
# Same options as C — install GCC via MSYS2 or use Visual Studio
# With MSYS2:
pacman -S mingw-w64-ucrt-x86_64-gcc

# Use g++ to compile C++:
g++ hello.cpp -o hello -std=c++17

# Visual Studio (MSVC):
# cl /std:c++17 hello.cpp

What people build with C++

Learn the basics first, then pick up these tools when a project needs them.

Practical uses

  • Build game engines and real-time graphics
  • Create browsers, databases, and desktop applications
  • Program robotics and low-latency systems
  • Optimize performance-critical libraries

Projects to try

  1. Terminal chess game
  2. Ray tracer
  3. Physics sandbox
  4. Small database engine

Common tools and packages

CMakeConanvcpkgBoostQtCatch2GoogleTestSDL

Well-known software

Unreal EngineChromePhotoshopBlenderMySQLLLVM