241: How To Use Raw Pointers Properly And Still Avoid Crashes.
Listen now
Description
Some people say that raw pointers are evil and should be avoided. Raw pointers are useful when used properly. This episode explains how to use raw pointers along with smart pointers and is taken from a recent game development session. I have a text-based role-playing adventure game that I’m working on with a main hero in the game. I want the hero to be able to move around. It wouldn’t be very adventurous if the hero had to stay in the same spot. This means I need to keep track of the hero’s location. Because this is a simple game, the location just needs an x and y coordinate. I decided to add a class that would manage multiple groups of properties. Grouping them together seemed like a good idea so it’ll be easier to understand an x property and a y property if they appear in a group called location. Listen to the full episode to understand where and why I chose to use unique_ptr to manage ownership of the groups and property values as well as how I used raw pointers when retrieving groups and property values.
More Episodes
This is the first in a series of comments about the book “How To Code C++ From a Simple Idea To a Game You’ll Understand!” Each episode will be short and focused. You can watch the video versions on YouTube at https://www.youtube.com/channel/UC4K_WBflLr2Cz0Sje_xTXkA You can also get your own copy...
Published 01/28/22
This is an interview with Conor Hoekstra about C++ algorithms and ranges. Conor presented my favorite talk at CppCon 2019 called Algorithm Intuition. I asked him to talk about algorithms on this podcast and he agreed. This just proves again why CppCon is the best place to be when you want to...
Published 09/25/19
Published 09/25/19