Why does making placeholder variable that I pass in a function give me a error?

This isn’t even valid C++.
To make an internal function (which will also be scoped only to its surrounding function,) use a lambda.

  auto Print = [&](float DisplayTime, FString const &DebugMessage) -> void {
    GEngine->AddOnScreenDebugMessage(-1, DisplayTime, FColor::Purple, DebugMessage);
  }

Even so, this is only available within the scope of the declaring function. To add a function to your DebugPrinter object, you need to put that declaration in the header file, as an inline function definition.

Also remember that UE4 by default uses C++14, so there’s even valid C++ parts that don’t work yet. This isn’t entirely EPIC’s fault – the UE has to run in a bunch of environments, including vendor-specific console devkits, that may have older compilers than you’d find if you just kept up with the latest and greatest.

1 Like