That’s not something different. It’s just a dereference and then dereference the returned value i.e.
In that code is the same as
FString Text1 = *PrtLog;
const TCHAR* Text2 = *Text1;
But without the use of extra variables.
- The first line creates an
- The next line creates a pointer to the variable declared on the line above.
* as part of a declaration is pointer and
& is a reference. As part of an expression
* means dereference and
& means address of
- And then the
** is as explained above, the first dereferences the pointer to get the
FString and then the next
* operator which gets a pointer to the first element of the character array (these are referred to as “C-style strings”).
Honestly, I don’t think this is very practical example of their usage. So lets take a look at function parameters.
void LogMessage(FString Message);
FString Message = TEXT("Some message");
LogMessage's parameter is taken by value this means that what
LogMessage gets is a copy of
Message; and assuming the definition of
LogMessage lives up to the name, it doesn’t need a copy of it, it’s just going to write it out to wherever and that’s it i.e. it only wants to read its contents.
What happens behind the scenes when you make a copy of an
FString is it’s going to allocate memory large enough to store that string and then copy its contents over, then at the end of the scope (end of the log function in this example) free it from memory. That’s a lot of unnecessary work when all it wanted to do was read its value.
So instead we should pass it by reference
void LogMessage(const FString& Message);
Message refers to the same object that the caller calls it with and not a copy of it. However this function shouldn’t need to modify
Message so it should be passed by