Access the address of the temporary variable

I found a lot of “const FSTring& Str = XXX.GetText().ToString();” in the engine, for example

FReply SSuggestionTextBox::OnKeyDown( const FGeometry& MyGeometry, const FKeyEvent& KeyEvent )
{
	const FString& InputTextStr = TextBox->GetText().ToString();
  1. The GetText() function declaration is FText GetText(), which may return either temporary or member variables
    2.ToString() is declared as const FString& FText::ToString() const

GetText().ToString() can cause problems accessing the address of temporary variables, and temporary variable destructions can cause the address to become an illegal value.

Ignore this, as these places allow const ref return value

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.