problem with compilation (intro to c++ programming with ue4) video 14

Hay guys
This is the first i post here so be gentle

I am using version 4.6.1 windows

I have a weak background with c++ (i use java mainly) so this might just be my fault

I have the following variables:

.h

.cpp

here is where i use all of them:

the above statement gives me this: Screenshot by Lightshot

i suspect WhatToSpawn is not a UClass (i don’t have any idea how though; isn’t UClass the parent of all the classes used by ue)

Try this instead:

APickup* const SpawnedPickup = (APickup*)World->SpawnActor(WhatToSpawn, SpawnLocation, SpawnRotation, SpawnParams);

this didn’t work

Sorry about this but i forgot to say this: I broke this

into 2 lines on purpose. the error is pointing for the 2nd line

another thing, the red line (error indicator) is under the “->” after “World”

This might help:

Alright try this: APickup* const SpawnedPickup = (APickup*)World->SpawnActor(WhatToSpawn, &SpawnLocation, &SpawnRotation, &SpawnParams);

Also when debugging if you right click in the output window and turn off intellisense errors you will be able to see your issue more clearly :slight_smile:

I found the source:


UWorld* const World = AActor::GetWorld();

was written as


UWorld const * World = AActor::GetWorld();

Can anyone explain the difference?

The first one is a pointer to a constant memory address. Meaning you can’t change which object it points at.

The second one treats the thing being pointed at as constant, you can’t alter the state of the object using this pointer.

I hope that made sense, it’s pretty late here.

Just in case here’s a short explanation of the differences between the two.

thank you very much

Beyond what was already said, a good trick I’ve found to understand pointer const-ness is to read it right to left. For instance:


UWorld const * World;

This reads as: “World is a pointer to a const UWorld

Whereas:


UWorld * const World;

This reads as: “World is a const pointer to a UWorld

Also:


UWorld const * const World;

This reads as: “World is a const pointer to a const UWorld

The only caveat is that the const keyword on the type can also be before the type for readability:


const UWorld * World; // synonym for UWorld const * World