Overloaded member function not found - function does not take 1 arguements

I’m getting the following build errors while trying to compile my code, despite it being identical to the ‘ShooterGame’ code. I can’t figure out exactly where the problem is occuring and the compiler isn’t pointing me to anywhere that can narrow it down.

The Error:

1>e:\thesommeue4\thesomme\intermediate\builddata\include\thesomme\../../../../Source/TheSomme/TheSommeWeapon.h(81): error C2061: syntax error : identifier 'ATheSommeCharacter'
1>E:\TheSommeUE4\TheSomme\Source\TheSomme\TheSommeCharacter.cpp(133): error C2660: 'ATheSommeWeapon::OnEnterInventory' : function does not take 1 arguments
1>E:\TheSommeUE4\TheSomme\Source\TheSomme\TheSommeWeapon.cpp(127): error C2511: 'void ATheSommeWeapon::OnEnterInventory(ATheSommeCharacter *)' : overloaded member function not found in 'ATheSommeWeapon'
1>          e:\thesommeue4\thesomme\intermediate\builddata\include\thesomme\../../../../Source/TheSomme/TheSommeWeapon.h(55) : see declaration of 'ATheSommeWeapon'
1>E:\TheSommeUE4\TheSomme\Source\TheSomme\TheSommeWeapon.cpp(522): error C2660: 'ATheSommeWeapon::OnEnterInventory' : function does not take 1 arguments

The areas of interest:
ATheSommeWeapon.cpp

void ATheSommeWeapon::OnEnterInventory(ATheSommeCharacter* NewOwner)
{
	SetOwningPawn(NewOwner);
}

void ATheSommeWeapon::OnRep_MyPawn()
{
	if (MyPawn)
	{
		OnEnterInventory(MyPawn);
	}
	else
	{
		OnLeaveInventory();
	}
}

TheSommeCharacter:

void ATheSommeCharacter::AddWeapon(ATheSommeWeapon* Weapon)
{
	if (Weapon && Role == ROLE_Authority)
	{
		Weapon->OnEnterInventory(this);
		Inventory.AddUnique(Weapon);
	}
}

Hi James,

That error typically means that the function you are implementing in your .cpp file has a different signature than the function you declared in your class. For instance, if your declaration was

virtual void OnEnterInventory();

but your implementation was

void ATheSommeWeapon::OnEnterInventory(ATheSommeCharacter* NewOwner)

Hope that helps!

Jeff

Hi Jeff, I checked that out but My Declaration is still the same in the header file, this is how it looks over there:

/** [server] weapon was added to pawn's inventory */
virtual void OnEnterInventory(ATheSommeCharacter* NewOwner);

Looking at the error output again, the first error is “syntax error : identifier ‘ATheSommeCharacter’” in the TheSommeWeapon.h header file. Guessing you need a

#include "TheSommeCharacter.h"

or maybe

#include "TheSommeGameClasses.h"

in your .cpp file. Another good idea would be to use the class keyword on your declaration to avoid any ordering issues, like so

virtual void OnEnterInventory(class ATheSommeCharacter* NewOwner);

Jeff

Thanks Jeff! Turns out adding the class keyword fixed the error…

Is there a particular reason my code requires that class keyword, whereas the shootergame example doesn’t?

Glad to help!

I’m guessing it works in ShooterGame because the precompiled header (ShooterGame.h) includes the relevant headers.

Jeff