For anyone looking for an explanation as to why we should need to dereference an FString - which is not a pointer - don’t worry… You’re not crazy. The course is just INCREDIBLY MISLEADING at this part.
In the documentation for FString, you’ll find this note, “When using %s parameters to include FStrings, the *
operator must be used to return the TCHAR required for the %s parameter.*”
So, what’s going on here (I think) is that an ancient implementation of string handling from the days of C (before there was even a # or ++) is used when you embed your string variables with %s. The string variable we want to print is stored in memory (more or less) as an array of CHAR’s.
[“H”,“e”,“l”,“l”,“o”," ",“W”,“o”,“r”,“l”,“d”,(END)]
So, the asterisk in *name points to the location in memory where this array of CHAR’s begins, allowing the TEXT() call to hop there when it adds to the explicit string.
But because this is the example used as the introduction to pointers - and because this extra asterisk is not explained - the student reasonably ends up thinking that they are dereferencing something they shouldn’t have to dereference. “I didn’t make an FString* pointer, I made an FString!” That is the correct and logical response. And you are right! Especially in lieu of how EXPLICIT C++ is everywhere else.
The asterisk used in this UE_LOG call is dereferencing an implicit array of CHARs behind the FStrings you are actually working with, because that’s just how the TEXT() call and %s works, apparently.
The course really should pause to note this. Not only to avoid the reasonable confusion, but to give another example of how pointers are used in the language.