Setting Timers

Hi all,

I am getting an error message which I can’t seem to debug and need fresh eyes to look over thusly:

CompilerResultsLog:   [1/4] ShooterController.cpp
CompilerResultsLog:    D:\Unreal Development\SimpleShooterVE\Source\SimpleShooterVE\ShooterController.cpp(9) : error C2572: 'AShooterController::GameHasEnded': redefinition of default argument: parameter 1
CompilerResultsLog:   D:\Unreal Development\SimpleShooterVE\Source\SimpleShooterVE\ShooterController.h(20): note: see declaration of 'AShooterController::GameHasEnded'
CompilerResultsLog:    D:\Unreal Development\SimpleShooterVE\Source\SimpleShooterVE\ShooterController.cpp(9) : error C2572: 'AShooterController::GameHasEnded': redefinition of default argument: parameter 2
CompilerResultsLog:   D:\Unreal Development\SimpleShooterVE\Source\SimpleShooterVE\ShooterController.h(20): note: see declaration of 'AShooterController::GameHasEnded'
LogMainFrame: MainFrame: Module compiling took 6.828 seconds

So, the problem is defintely the GameHasEnded function call in ShooterController.h or Shooter Controller.cpp but I can’t see it

In ShooterController.h I have this:

public:
	//GameHasEnded override
	virtual void GameHasEnded(class AActor *EndGameFocus = nullptr, bool bIsWinner = false) override;

And in ShooterController.cpp I have this:

void AShooterController::GameHasEnded(class AActor *EndGameFocus = nullptr, bool bIsWinner = false) {
	//because it overridden must use super
	Super::GameHasEnded(EndGameFocus, bIsWinner);

	UE_LOG(LogTemp, Warning, TEXT("We have been Killed") );

}

Would someone please be able to point out the error I have made. Any help would be very much appreciated.

Regards.

You can only add default arguments on the declaration.

int square(int n = 3); // declaration

int square(int n) // adding "= 3" here is an error
{
    return n * n;
}

int main()
{
    int value = square(); // Ok, uses default argument of 3 i.e. call is square(3)
}

You can only add it on the definition if it’s also the declaration of it

int square(int n = 3)  // Ok, declaration as well as definition.
{
    return n * n;
}

int main()
{
    int value = square(); // Ok, uses default argument of 3 i.e. call is square(3)
}
2 Likes

Got it DanM. Thanks a lot for that I’ll have to keep that in mind - I wish I could setup Visual Studio Community to automatically setup function definitions into the class like Sam does, it would solve these types of problems from occurring. Anywayz, Now that I have the code fixed and compiling, I have run into another problem :worried:.

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

Privacy & Terms