Breaking down pointers for me

Before I continue with the course I would just like to have some help to break down for me how we are using pointers with Unreal Engine. Take this pointer declaration and later use as an example:

^ Here we are declaring/creating a pointer called PressurePlate, that points to the content of the class ATriggerVolume. This is the same as instantiating a class, like we did with FBullCowGame BCGame, only now we’re using a pointer.

^ Here we are accessing the content of the class ATriggerVolume and using one of its functions created by the Unreal Engine developers.

So I guess one of the questions I have is, if this class was directly #include’ed into our cpp file, we would be able to access and use the function with just using the “.” operator, right?

I’m just not completely seeing how the pointer is accessing the class and how the class is connected to our cpp file if it isn’t #included.

I can see the cIass is located here:

Is it just because the class is located anywhere in the solution that we can access it with pointers?

This has nothing to do with it being a pointer. It’s just that somewhere in the build chain ATriggerVolume is known to the file, just like FMath, AActor, TArray etc.

Could you please explain a little more where I was wrong?

No, because it’s a pointer. You access data members from pointers wth the arrow operator.

The ATriggerVolume class is connected to the cpp file in the same manner a lot of other Unreal classes are.

I was a little unclear there. What I meant is if the class was directly #include’ed into our cpp file, we would be able to make an instance of it instead of a pointer, like this:

ATriggerVolume PressurePlate;

and then access its functions with the “.” operator.

I think I’m just trying to make sure that we’re not doing anything more magical with the pointers than we were doing with the #included classes and functions we made , only now the class is further away with functions other people made.

No, the class known to the file so is effectively already #included. If it wasn’t then the line ATriggerVolume* PressurePlate wouldn’t compile since it wouldn’t know what ATriggerVolume is

A pointer is only a memory address. It’s not some further form of abstraction.

BCGame Game;
BCGame* pGame = &Game; // create pointer to first variable 
pGame->PlayGame();

Thank you very much for your time! This was very helpful :slight_smile:

1 Like

Hello,
Dan’s explanations are a bit confusing to me.
I’m glad you understand it now Bendik, but I would like to offer an alternative explanation.

I have a class called House.
Regardless if I want to instantiate it or make a pointer I have to include:

#include “House.h”

House house; // this creates a house and gives me the whole thing.
House* housePtr; // this creates a house and only gives me the adress.

If I want to access the color of the house I need to write:
house . color
housePtr -> color
The result will be the same, the only difference is how you ACCESS the color by using different operator symbols.

So, " . " and " -> " has nothing to do with #include’ing the class.
You ALWAYS have to include it to be able to use it.

The reason why you don’t need to include “ATriggerVolume.h” manually to be able to use it, as in your example, is because it is already included in an even bigger header file.

If my House class was already included in another header file called City, I would automatically include “House.h” when I include “City.h”.

Privacy & Terms