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.