Why FString::Printf() doesn't take Fstrings as reference but instead using the overloaded* ?

Hello!

I’m new to UE but I have years of experience with C++. Check the following code:

FString new_str = FString::Printf( TEXT("Hidden Word: %s"), *m_hiddenWord );

If I was implementing a method like Printf() I would probably accept references to do my work like this:

FString new_str = FString::Printf( TEXT("Hidden Word: %s"), &m_hiddenWord );

Digging inside Visual Studio, I saw that the overloaded FString operator * returns an ElementType* but this is as far as I could dig into the UE implementation.

Why did they do it this way? Is it faster for some reason to do it this way, instead of taking the reference of the FString object and using it to extract the characters information that Printf needs?

Thank you.

Because this operator turns your string into a TCHAR* character array, and most functions expect this type. Or at least something along this line I believe.

2 Likes