Help understanding !PlayerPawn

I want to preface this by saying that I came into this course with previous experience and a decent understanding of C++. I know the general use of the ! operator, example

bool bDone = false;
while(!bDone)
{
     //do something...
}

Generally ! means not. So the above code runs because not false is true. Based on this the way I try to understand !PlayerPawn is this: PlayerPawn is a pointer to an Actor. If the actor doesn’t exist, we get a nullptr. So wouldn’t this basically say if(!nullptr)? What is a not nullptr? Another way it seems you can phrase this is if(![Player Pawns Exists]) then… but if player pawn doesn’t exist, then !PlayerPawn implies it does exist. So I’m just trying to understand what the ! operator is doing on actors, or well i guess in this case pointers.

Pointers are implicitly convertible to bool. nullptr is converted to false, any other value to true.

A prvalue of arithmetic, unscoped enumeration, pointer, or pointer-to-member type can be converted to a prvalue of type bool
A zero value, null pointer value, or null member pointer value is converted to false; any other value is converted to true

So

if (!PlayerPawn)
{
}

is equivalent to

if (PlayerPawn == nullptr)
{
}
1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms