Skip to content
Justice Tech School

C++ Tutorial

Powerful, fast code for games, systems and performance.

Start learning C++
Getting started4 lessons
  1. 1C++ IntroductionWhat C++ is and where it is used.
  2. 2Syntax and Outputcout, endl and comments.
  3. 3C++ Get StartedInstall g++, clang or Visual Studio.
  4. 4C++ Comments// starts a one line comment and /* */ spans several lines.
Basics21 lessons
  1. 5Variables and Typesint, double, char, bool and string.
  2. 6User Inputcin and getline.
  3. 7OperatorsArithmetic, comparison and logic.
  4. 8StringsThe string class.
  5. 9Math Functionscmath helpers.
  6. 10C++ Data TypesBasic types: int, long, short, float, double, char, bool and std::string.
  7. 11Constants and Castsconst and constexpr declare constants, constexpr at compile time.
  8. 12Enums and Structsenum class defines scoped, type safe constants.
  9. 13C++ String Methodsstd::string has size, empty, substr, find, replace, append, insert, erase and comparison.
  10. 14Input and Output Streamscout prints and cin reads.
  11. 15Math and Random Numbers<cmath> has sqrt, pow, abs, floor, ceil and round.
  12. 16Variables and TypesC++ is statically typed.
  13. 17cout and cincout prints with << and cin reads with >>.
  14. 18std::stringstd::string grows automatically.
  15. 19Reading Linesgetline reads a whole line.
  16. 20const and constexprconst values cannot change.
  17. 21CastingUse static_cast for safe conversions.
  18. 22ReferencesA reference is another name for a variable.
  19. 23PointersA pointer stores an address.
  20. 24NamespacesNamespaces group names and avoid clashes.
  21. 25OperatorsArithmetic, comparison, logical and bitwise operators.
Control flow11 lessons
  1. 26If and SwitchDecisions.
  2. 27Loopswhile, do...while, for and range-based for.
  3. 28switch, Ternary and Range Forswitch matches integers and enums, the ternary operator is a short if, and a range based f.
  4. 29while, do while and breakwhile checks before, do while checks after.
  5. 30Structured Bindings and if initStructured bindings unpack pairs, tuples and structs into variables.
  6. 31if, else if and elseBranch with conditions.
  7. 32switchswitch compares an integral value with cases.
  8. 33Loopsfor, while and do while repeat code.
  9. 34Range based forfor (auto x : c) copies, for (auto& x : c) modifies and for (const auto& x : c) reads with.
  10. 35break and continuebreak leaves a loop and continue skips a round.
  11. 36Structured BindingsUnpack pairs, tuples and structs into named variables.
Functions14 lessons
  1. 37FunctionsReusable blocks of code.
  2. 38Lambdas and RecursionSmall functions and self calls.
  3. 39Reference and Default ParametersPass by reference (&) to avoid copies and to change the caller variable.
  4. 40Function TemplatesA template writes one function for many types.
  5. 41inline, constexpr and noexcept Functionsconstexpr functions can run at compile time.
  6. 42std::function and Callbacksstd::function stores any callable: functions, lambdas and functors.
  7. 43FunctionsA function has a return type, name and parameters.
  8. 44Default ArgumentsGive parameters default values.
  9. 45Function OverloadingSame name with different parameter types.
  10. 46Pass by Value, Reference and const ReferencePass by value copies.
  11. 47LambdasA lambda is an inline function.
  12. 48std::functionstd::function stores any callable and is handy for callbacks.
  13. 49Function TemplatesTemplates write one function for many types.
  14. 50RecursionA function may call itself with a base case.
Data structures22 lessons
  1. 51Arrays and VectorsFixed and growing lists.
  2. 52Maps and SetsKey and value pairs and unique values.
  3. 53Pointers and ReferencesAddresses and aliases.
  4. 54Dynamic Memory and Smart Pointersnew, delete and unique_ptr.
  5. 55Vector In Depthvector grows automatically.
  6. 56array, deque and liststd::array is a fixed size array with a size, deque is a double ended queue and list is a .
  7. 57map, unordered_map and multimapmap keeps keys sorted, unordered_map uses hashing and is usually faster, and multimap allo.
  8. 58set, stack, queue and priority_queueset keeps unique sorted values, stack is last in first out, queue first in first out, and .
  9. 59pair, tuple, optional and variantpair and tuple group values, optional holds a value or nothing and variant holds one of se.
  10. 60string_view and Iteratorsstring_view is a cheap read only view of text without copying.
  11. 61std::array and C Arraysstd::array has a fixed size and safe helpers.
  12. 62std::vectorvector is a resizable array.
  13. 632D VectorsA vector of vectors makes a grid.
  14. 64std::mapmap stores sorted key value pairs.
  15. 65unordered_map and unordered_setHash based containers give fast average lookup but no order.
  16. 66std::setset keeps unique values sorted.
  17. 67stack and queuestack is last in first out and queue is first in first out.
  18. 68pair and tuplepair holds two values and tuple holds many.
  19. 69Algorithms<algorithm> has sort, find, count, reverse, min_element, max_element, accumulate and more.
  20. 70Custom SortingPass a comparator or lambda to sort.
  21. 71IteratorsIterators point at elements.
  22. 72optional and variantoptional holds a value or nothing.
Object oriented programming19 lessons
  1. 73Classes and ObjectsBundling data and behaviour.
  2. 74Inheritance and PolymorphismExtending classes.
  3. 75Operator Overloading and TemplatesCustom operators and generic code.
  4. 76Constructors, Destructors and RAIIConstructors set up an object and destructors clean up.
  5. 77Access Control, const and friendpublic, protected and private control access.
  6. 78static Members and thisstatic members belong to the class, shared by all objects.
  7. 79Copy and Move SemanticsThe copy constructor duplicates an object, while move steals resources from a temporary, w.
  8. 80Virtual Functions and Abstract Classesvirtual functions are resolved at runtime.
  9. 81Multiple Inheritance and InterfacesA class can inherit from several bases.
  10. 82ClassesA class has data and member functions.
  11. 83Constructors and DestructorsThe constructor sets up an object and the destructor cleans up when it ends.
  12. 84InheritanceA derived class inherits from a base.
  13. 85Abstract ClassesA pure virtual function (= 0) makes a class abstract.
  14. 86Operator OverloadingDefine + and << for your types to make them natural to use.
  15. 87static Membersstatic members belong to the class and are shared by all objects.
  16. 88structstruct is a class with public default access.
  17. 89enum classScoped enums avoid name clashes and do not convert to int by accident.
  18. 90Smart Pointersunique_ptr owns one object, shared_ptr shares ownership.
  19. 91Move Semanticsstd::move turns a value into an rvalue so its resources can be moved instead of copied.
Standard library and files15 lessons
  1. 92Algorithms and Iteratorssort, find, count and more.
  2. 93Exceptionstry, catch and throw.
  3. 94Filesifstream and ofstream.
  4. 95More STL Algorithms<algorithm> offers sort, find, count_if, transform, accumulate, remove_if, unique, reverse.
  5. 96File Streamsofstream writes and ifstream reads files.
  6. 97chrono and filesystem<chrono> measures time and <filesystem> works with paths and directories (C++17).
  7. 98Regular Expressions and Text<regex> matches patterns with regex_match, regex_search and regex_replace.
  8. 99Exceptionsthrow an exception and catch it with try catch.
  9. 100File Streamsofstream writes and ifstream reads files.
  10. 101stringstreamstringstream builds and parses text like a file.
  11. 102chrono and random<random> makes good random numbers and <chrono> measures time.
  12. 103string_viewstring_view looks at text without copying it.
  13. 104Practice: Word FrequencyUse a map to count words.
  14. 105Practice: PalindromeCompare a string with its reverse.
  15. 106Practice: Top ScoresSort a vector of pairs and print the top two.
Advanced C++Premium8 lessons
  1. 107Smart Pointersunique_ptr owns an object exclusively, shared_ptr shares ownership with reference counting.
  2. 108Class TemplatesClasses can be templates too, such as a generic Stack.
  3. 109Concepts and Constraints (C++20)Concepts name requirements on template parameters, giving clear error messages.
  4. 110Lambdas In DepthLambdas capture by value [x], by reference [&x], everything [=] or [&], and can be mutable.
  5. 111Rvalue References and Perfect ForwardingT&& binds to temporaries, enabling moves.
  6. 112Threads, Mutexes and Atomicsstd::thread runs functions concurrently, mutex and lock_guard protect shared data and atom.
  7. 113async, future and promisestd::async runs a task possibly on another thread and returns a future.
  8. 114Exceptions and Exception SafetyThrow by value, catch by const reference and derive from std::exception.
C++ in practicePremium7 lessons
  1. 115CMake and Build SystemsCMake generates build files from CMakeLists.txt.
  2. 116Testing with GoogleTest and Catch2Unit test frameworks such as GoogleTest and Catch2 provide test cases and assertions.
  3. 117Debugging and SanitizersUse gdb or lldb for stepping, -fsanitize=address,undefined for runtime checks, valgrind fo.
  4. 118Performance and OptimisationCompile with -O2, measure before tuning, prefer vectors to lists, reserve capacity, avoid .
  5. 119Libraries, Modules and PackagesPackage managers such as vcpkg and Conan fetch libraries like Boost, fmt and nlohmann json.
  6. 120Where C++ Is UsedC++ powers game engines such as Unreal, browsers, databases, finance systems, embedded dev.
  7. 121C++ Best PracticesFollow the C++ Core Guidelines: use RAII, smart pointers, const, auto where clear, range f.
Next steps2 lessons
  1. 122What Next?Where to go after the basics.
  2. 123Practice ProjectsBuild a text adventure, a to do list with file saving, a small game with SFML, a JSON pars.