Why do we need to dereference?

Hi there!
getting struggled here… The game is working fine but I just can’t understand why do we need to dereference these two :sob:

UE_LOG(LogTemp, Warning, TEXT("Location: %s, Location: %s"),
	*PlayerViewPointLocation.ToString(),
	*PlayerViewPointRotation.ToString()
);

Any explanation will be awesome!

Okay, so no one else has answered, I’ll maybe offer one even though I don’t know much

I’m guessing it has to do with the fact that C++ doesn’t have strings, but instead it has arrays of Chars. Technically you using an array, which you’d use a reference for and dereference if using in this case. Maybe.

OR

It’s actually an overload operator having something to do with the TEXT format.

It is the latter. FString has the *() operator overloaded to return a TCHAR * string. They probably used the dereference operator because it behaves like a (smart) dereference.

FString C++ doc

Scroll down 3/4 of the way to see the operator descriptions. Not sure why it says “…if Num…”, maybe a typo assuming it means if set.

btw - C++ does have strings std::string

2 Likes

Thanks for the explanation!

What I meant was, the standard library includes ways to use strings, but from what I understand it’s actually an array of chars in the background. Which is a round about way of saying C++ doesn’t actually support strings, but libraries for C++ do.

Well then it might be a case of semantics since the standard library is part of the language specification therefore C++ does support strings even if the core language did not (without the standard <string> header) though wouldn’t the null terminated char array eg. char* carray = "Hello World" still be considered a type of string (or more specifically a “c-type” string)? and I am pretty sure that is supported in the language core.

I would agree, it is likely semantics on what is ‘supported’. The library works behind the scenes to make C++ support strings even though it doesn’t natively.

Privacy & Terms