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

Hello, I have code like this:

// Fill out your copyright notice in the Description page of Project Settings.

#include "DebugPrinter.h"
#include "iostream"

	void Print(float DisplayTime, std::string DebugMessage);
		GEngine->AddOnScreenDebugMessage(-1, DisplayTime, FColor::Purple, TEXT(DebugMessage));

	Print(3.0f, "DebugPrinter Initialized");


now this gives me an error on the DebugMessage and DisplayTime why? Also not I’m new to c++ dont roast me please.

You shouldn’t use the standard library with Unreal Engine. Use FString instead.

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

Yikes alright that’s a lot to unpack like I said I’m a newbie and you just flipped me on my head with this paragraph. But thanks for your feedback.