
Welcome to C++ for Games. During this course, you will learn the basics of C++.
During this course, I will cover the following topics:
Using Microsoft's Visual Studio to create games
Using Git to keep your source code safe and in the cloud
Fundamental data types
Pointers and references
Control flow
Functions
Arrays
Classes
And more...
By the end of the course, you will be proficient in C++ and be able to make simple 2D games from scratch.
In this video, I will show you how to download and install Visual Studio.
In this hands-on lab, you will download and install Visual Studio Community Edition.
Learn to write your first C++ program called "Hello World!".
You will use Visual Studio to create a new C++ project and add a C++ source file that prints the text "Hello, World" to the console.
In this hands-on lab, you will create your first C++ application.
Your first program will print the text "Hello, World!" to the console.
In this lesson, you will learn about Git. Git is a distributed Version Control System (VCS) that let's you track the changes of your code over time.
You will learn how to create a Git repository on GitHub.com and how to add new files to your repo and push those changes to GitHub.
In this hands-on lab, you will create a Git repository on GitHub.com and upload your C++ for Games project to GitHub.
You will learn about
Creating a repository
Adding files to the repo
Committing changes to the repo
Pushing the changes to GitHub.com
This lecture describes the various steps to building your C++ application. In this lecture, I'll cover:
Preprocessor
Compiler
Assembler
Linker
I'll also talk about why we use header files in C++ and what a translation unit is.
In this hands-on lab, I'll talk about the different stages of the C++ build process.
You'll learn about header files, source files, and the One-Definition-Rule (ODR).
After the lesson, you will understand what a translation unit is and how to declare a function that is defined in a different translation unit.
Learn about how to use the standard input & output streams in C++.
You will also learn how handle unexpected input and how to wait for the user to provide input.
In this hands-on lab, you will learn how to read input and write output to the standard input/output streams in C++.
You will also learn how handle unexpected input and how to wait for the user to provide input before closing the console window.
This lecture covers reading and writing to files in C++.
You will learn to use ifstream and ofstream to read and write both text (ASCII) and binary files.
You will also learn how to handle the various errors that can occur when reading and writing to files.
In this hands-on lab, you will learn to use the filestream header file to create input and output files.
You will also see how you can read and write ascii (text) files as well as binary files.
In this section, you will be introduced to the fundamental data types. You will learn about
Integrals
Enumerations
Floating-points
Booleans
Characters
Type conversion
In this lecture, you will learn about the various integral types such as:
int (long)
unsigned int
short
long long
std::size_t
and integral literals
In this hands-on lab, we'll practice with the integral data types and show the size and representable values of integral types.
An enumeration allows you to define a list of named integral constants called enumerators.
This allows you to use human-readable names in your C++ source code where the names will be replaced by their integral values by the compiler.
In this hands-on lab, we'll look at a few ways to define and use enumerations in C++.
In this lesson, you will learn about
float
double
long double
floating-point literals
In this hands-on lab, we'll take a look at float, double, and long doubles in C++.
Booleans (bool) are used to store the result of a boolean expression that evaluates to true or false.
In this lesson you will also learn about boolean literals (true and false) and the boolean operators AND (&&) and OR (||) and NOT (!).
In this hands-on lab, we'll look at booleans and a the boolean operators AND (&&), OR (||) and NOT (!).
In this lesson, you will learn about the different character types in C++.
char
wchar_t
char8_t
char16_t
char32_t
Character literals
In this hands-on lab, we'll look at the different character types in C++ and how to express character and string literals for each of the different character types.
The auto keyword in C++ is used to allow the compiler to deduce the type of a variable.
In this hands-on lab, we'll see a few ways to use the auto keyword in C++.
I'll show you an example where auto can be used to make your code a bit more succinct.
When you assign a variable of one type to a variable of a different type, then the compiler needs to perform a conversion. When this conversion results in some loss of information (either in the range or the precision of the value) then an explicit conversion is required to inform the compiler that the conversion was intended.
In this hands-on lab, we'll look at implicit and explicit type conversions and when it is safe to rely on implicit type conversions and when you need explicit type conversions.
Master the power of pointers and references in C++! This lesson provides a comprehensive overview of these crucial concepts, including:
Declaring and initializing pointers and references
The dereference operator (*) and the address-of operator (&)
Passing arguments by reference
Dynamic memory allocation with new and delete
Pointer arithmetic (briefly) Whether you're a beginner or looking to solidify your understanding, this video will equip you with the knowledge you need to confidently use pointers and references in your C++ programs.
Get hands-on with C++ pointers and references! In this hands-on lab, I will walk you through practical examples, showing you exactly how to declare, initialize, and use pointers and references in real code. Follow along and code with me to solidify your understanding!
In this lesson, you will learn:
What is an array?
Defining arrays
Initializing arrays
Accessing elements
Multidimensional arrays
Using arrays as pointers
In this hands-on lab, I will show you a few examples of declaring arrays, initializing arrays, and looping through the elements of the array.
This lecture introduces C++ smart pointers (std::unique_ptr, std::shared_ptr, std::weak_ptr) as modern solutions for automatic memory management. Learn how they prevent common memory leaks and dangling pointers, making your C++ game code safer and more robust.
In this interactive lab, solidify your understanding of std::shared_ptr's reference counting and std::weak_ptr's non-owning observation. Through coding examples, you'll learn to correctly manage shared object lifetimes and gracefully handle cases where observed objects might no longer exist.
In this interactive lab, you'll learn the concept of unique ownership with std::unique_ptr. Through practical coding examples, you'll learn its efficient use for preventing memory leaks, creating exception-safe code, Resource Acquisition Is Initialization (RAII), and designing clear ownership hierarchies in your C++ projects.
In this lesson, we will look at operators and operands in C++. We will also cover the following operators:
Unary
Binary
Arithmetic
Modulo
Increment and decrement
Logical
Comparison
Three-way comparison
I will also talk about Boolean conversions.
In this hands-on lab, we'll look at the various operators in C++.
In this lesson, we will look at bitwise operators. We will cover the:
Bitwise logic operators
Bitwise NOT, AND, OR, and XOR
Left shift operator (<<)
Right shift operator (>>)
In this hands-on lab, we will look at:
Bitwise logic operators (|, &, ^, ~)
Using a bit mask to mask off the bits of an integral
Left-shift operator (<<)
Right-shift operator (>>)
Sign padding of signed integrals
This lesson covers the following flow control constructs:
if-else
switch
while loop
do-while loop
for loop
range-based for loop
In this hands-on lab, you will learn how to use the flow control expressions in C++ to create complex programs with conditional expressions.
In this lesson, you will learn about functions in C++. Functions are one of the fundamental building blocks of most programming languages. A function allows you to define a reusable block of code that can be invoked many times.
In this lesson, you will learn
How to define a function
The return statement
How to invoke a function
The stack
Pass by value
Pass by pointer
Pass by reference
Default arguments
Function overloading
Function pointers
In this hands-on lab, we'll look at examples of using functions. We'll look at
Defining a function
The return statement
Invoking functions
Pass by value
Pass by pointer
Pass by reference
Function overloading
Function pointers
Type aliases for function pointers
In this lesson, I will cover the following topics:
Function template definition
Template type deduction
Return type deduction
Abbreviated function templates
In this hand-on lab, I will show you a few practical examples of creating function templates and how to use them. This lab will cover:
Defining function templates
Template parameters
Return type deduction
decltype(auto)
Abbreviated function templates
auto type deduction
In this lesson, you will learn about Lambdas in C++. Lambdas are a way to define a function that can be used like a first-class object in C++. Lambdas can be passed to functions or returned from functions making C++ a more "functional" programming language.
We'll also cover:
Lambda expressions
Generic lambdas
Lambda captures
std::function
In this hands-on lab, I will show you a few examples of using lambdas in C++. I will show you:
How to define a lambda and store it in a variable.
Capture clause
Generic lambdas
Explicit template parameters
In this lesson, you will learn about Object Oriented Programming (OOP). OOP is a programming methodology where you use classes to represent different objects in your game.
In this lesson, I will cover the following topics:
What is OOP?
SOLID principals
Encapsulation
Inheritance
Polymorphism
In this lecture, I will describe classes in C++. I will cover the following topics:
Defining a class
Member variables
Member functions
Constructors & Destructors
Public, protected, and private visibility
The this pointer
Struct
Union
In this hands-on lab, I will talk about defining a class and class constructors.
In this hands-on lab, I will talk about the explicit keyword used with constructors. Marking a constructor explicit can prevent some weird hard-to-find bugs later in your code.
Use explicit on your constructor to prevent your class from being constructed using the constructor parameters. In this lesson, I will explain why that is important.
In this hands-on lab, I'll talk about destructors. These are special member functions of a class that are automatically invoked when the class is destroyed (either by going out of scope or when an instance of the class is explicitly deleted).
In this hands-on lab, I will talk about copy constructors for classes in C++.
A copy constructor can be used to clone an instance of a class to another.
In this hands-on lab, I will talk about inheritance.
Inheritance allows one class to inherit the member variables and member functions of another class.
In this hands-on lab, I talk about polymorphism.
Polymorphism is the ability to change the behavior of the parent class in a child class. This is achieved through overriding virtual functions in the child class.
In this hands-on lab, I talk about pure virtual functions.
A pure virtual function is a function that you must override in the child class. A class with a pure virtual function is called an abstract class and can't be directly instantiated. A child class that implements all pure virtual functions of it's parent class(es) is called a concrete class and can be instantiated.
In this hands-on lab, I highlight the differences between the class and struct keywords.
The members of a struct have public visibility by default, whereas the members of a class are private by default. Struct inheritance is public by default. Class inheritance is private by default.
In this hands-on lab, I show how you can separate the class declaration and definitions into header files and source files.
In this lesson, I describe class templates. You will learn how to define a class template. You will learn about type and non-type template parameters and how to specialize class templates.
In this hands-on lab, I create a vector class that can have any type and any number of vector components.
Alias templates allow you to create an alias to your class template that specifies some (or all) of your template parameters.
In this hands-on lab, I show how you can use the "deducing this" feature introduced in C++23 to implement the array subscript operator on a class template.
In this hands-on lab, I show you how to create a template specialization for a class template.
Creating a class template specialization requires that you specialize the entire class (including all of the member functions of the class). In this video, I'll show you how to "lift" the part of the class that you want to specialize into a base class to avoid having to reimplement the entire class template.
In this hands-on lab, I talk about explicit template instantiation.
Explicit template instantiation will force the the compiler to instantiate (and compile) your class template given a specific set of template parameters.
Move semantics allow you to define a function that allows objects to be moved (instead of copied). This is useful to avoid expensive copy operations when a move would suffice.
In this hands-on lab, I show you how to implement move semantics on your classes.
In this lesson, I provide a brief introduction to operator overloading. I talk about defining operators as member functions of your class as well as defining operators as free functions.
In this hands-on lab, I show how to define the addition operator for a class.
In this lesson, I talk about overloading the assignment and compound assignment operators on your class.
The assignment operator defines what happens when you "assign" (using the "=" operator) one instance of a class to another and the compound assignment operators combines assignment with another operator (such as "+", "-", "*", or "/")
In this hands-on lab, I show you how to overload the assignment and compound assignment operators on your classes.
In this lesson, I talk about unary operators.
A unary operator works with only a single operand. Some unary operators are the negation, (-a), pre-increment (++a), pre-decrement (--a), post-increment (a++) and post-decrement (a--).
In this hands-on lab, I add the negation, pre & post increment & decrement operators to the Vector2 class.
In this lesson, I talk about overloading the array subscript operator.
The array subscript operator allows your class to behave like an array. You need to overload both the const, and non-const versions of this operator. You can use an explicit object member function (or deducing this) introduced in C++23 to avoid the code duplication required for the array subscript operator.
In this hands-on lab, I show you how to implement the array subscript operator to the Vector2 class. I also show how to define an explicit object member function to remove the code duplication required when implementing the const and non-const versions of the array subscript operator.
In this lesson, I show you how to implement the 6 comparison operators for your class.
Most of the time, it is sufficient to define the less-than ("<") operator and the equality operator ("=="). The greater-than (">"), less-than or equal to ("<="), and greater-than or equal (">=") operators can be defined in terms of the less-than operator. The inequality ("!=") operator can be defined in terms of the equality operator.
The three-way comparison operator ("<=>") added in C++20 allows you to define all 6 comparison operators with a single function.
In this hands-on lab, I show you how to implement the 6 comparison operators on your class.
I also show how you can use the three-way comparison operator added in C++20 to generate all 6 comparison operators using a single function. The three-way comparison operator can be automatically generated by the compiler or you can explicitly define it for your class.
In this lesson, I show you how you can add operators to you class that can convert your class to another type. Implicit conversion constructors and implicit conversion operators allow your class to be used used in the context of another type.
In order to prevent implicit conversions, you can use the explicit keyword to prevent the compiler from performing implicit conversions on your class.
In this hands-on lab, I show you how you can implement the type conversion operators on your class.
In this lesson, I show you how to create user-defined literal suffix for your class.
A user-defined literal suffix allows you to convert literal values (strings, integer, or floating-point literals) to your class type. Literal suffix is used to express the "units" of a literal value. For example, "30_C" can be used to represent a temperature value in Celsius.
In this hands-on lab, I show you how to implement a user-defined literal suffix for temperature values.
This lecture explores the evolution of error handling in C++, tracing its journey from C-style mechanisms like return codes and global error states to modern approaches, including the introduction of exceptions and advancements in C++23.
This lecture explores the foundational error handling mechanisms inherited from C that remain relevant in modern C++ today. This lecture details approaches like return codes and error flags, where functions return special values to indicate success or failure, noting their simplicity, minimal overhead, and determinism, but also their limitations in expressiveness and ease of being ignored.
In this hands-on lab, we'll look at traditional error handling techniques. Specifically, we'll look at
Return codes
Output parameters
In this hands-on lab, we'll look at using callback functions.
Callback functions are function pointers that get invoked when an error occurs in another function. Callback functions can be used to report errors. This is common in some 3rd party libraries that don't support exceptions (any C library).
This lecture introduces C++ exceptions as a structured mechanism for managing errors by separating error detection from error handling. We'll cover the basic syntax and semantics of exception handling including the use of try, throw, and catch.
In this hands-on lab, we'll look at standard exception syntax including try, throw, and catch. We'll use standard exceptions from the Standard Template Library.
This lecture builds upon exception fundamentals, exploring more sophisticated techniques for managing errors in complex C++ applications. We'll cover
Custom exception hierarchies
Nested exceptions
Function-try blocks
In this hands-on lab, we'll look at practical use-case examples of creating custom exception hierarchies. We'll also look at throwing and catching nested exceptions.
This hands-on lab extends the previous lab with use case examples of function-try blocks.
Welcome to the C++23 for Games Programming course. This course is designed to teach you how to program in C++ by making a simple 2D game from scratch. Whether you are a just starting out in higher education or a “lifelong learner”, this course will give you the knowledge and skills needed to be an effective C++ programmer.
Being literate in programming is an increasingly important skill to have. Programming languages like Python, Rust, C, and C++ are used in many different industries including research, finance, artificial intelligence, data science, and video games. This course aims to teach you how to solve programming problems at a higher level. By learning the fundamentals of C++ through a game programmer's perspective, you will not only be learning how to tackle complex programming problems, but you’ll also have fun doing it!
This course does not assume that you have any prior programming experience. The course covers the fundamentals of C++ programming and by the end of the course, you will be able to create a simple 2D game written in C++.
You will be using GitHub to keep your work for your programming assignments. GitHub not only allows you to safely store your precious source code in the cloud, but also to start a professional programming portfolio that may eventually be used to find your dream job.