Pointer to string


If FString ObjectName = GetOwner().GetName();

here ObjectName as ben said is pointer to string which is name of that owner. But if its pointer to string shouldn’t it be FString *ObjectName and not FString ObjectName?

UE_LOG(LogTemp, Warning, TEXT(Position Report reporting for duty on %s), *ObjectName)

Ben told that FString is for string. To print it we should have passed the base address with ObjectName

printf("%s", ObjectName);

or in case of C++ we have

printf("%s", ObjectName.c_str());

??? I am confused by what is FString ObjectName(is it string or pointer to String?)

If its a pointer to string than why don’t we have FString *ObjectName. Also out of curiosity does FText has also same behaviour?


FString Name is not a pointer but contains the string.
You get confused about the UE_Log, because it uses *Name as a way to access the string.

This is the macro (UE_LOG) only. Otherwise you would just use ‘Name’ as it is the Fstring and not a pointer :slight_smile:


Thanks :blush:


I solved the quiz and I know it better now

  • ObjectName is an FString. Why do we have to use *ObjectName in our UE_LOG rather than just ObjectName?

UE_LOG is expecting a TCHAR array, and the * effectively converts the string to this type.

That’s right, just live with it for now, it’ll make more sense to you if you’re a C++ beginner as we go on.