1. Home
  2. UE5 Compilation Errors
  3. UE5 C++ Compilation Error...
  4. C2556: Function Declaration Is Different from Previous Declaration

C2556: Function Declaration Is Different from Previous Declaration

What It Means & How to Fix It


🧠 Why You’re Seeing This Error

The C2556 error means you declared a function in one place (typically in a header file), and then defined it somewhere else (like in a .cpp file), but the two declarations don’t match — even slightly.

In UE5, this often happens when:

  • You accidentally change the return type or parameters between .h and .cpp
  • You forget const on a method in one place but not the other
  • You mismatch UFUNCTION() declarations with the actual definition
  • You’re overriding a function from a base class but change its signature

💥 Example Error Message

error C2556: 'float GetSpeed()' : overloaded function differs only by return type from 'int32 GetSpeed()'

🛠️ Example Code

// MyActor.h
UCLASS()
class AMyActor : public AActor
{
GENERATED_BODY()

public:
float GetSpeed(); // Declared as float
};
// MyActor.cpp
int32 AMyActor::GetSpeed() // ❌ C2556: return type doesn't match
{
return 600;
}

✅ How to Fix C2556 in UE5 – Step-by-Step


✔️ 1. Make Sure Return Types Match Exactly

Wrong:

float GetSpeed(); // in header
int32 GetSpeed() { return 500; } // in .cpp ❌

Fix:

float GetSpeed(); // ✅ Same return type
float AMyActor::GetSpeed() { return 500.f; }

✔️ 2. Check for const Mismatch

Wrong:

FVector GetLocation() const; // in .h
FVector AMyActor::GetLocation() { ... } // in .cpp ❌ missing const

Fix:

FVector AMyActor::GetLocation() const { ... } // ✅ match const

✔️ 3. Match Parameters Exactly

Wrong:

void SetHealth(float Value); // in .h
void AMyActor::SetHealth(int32 Value) { ... } // ❌ wrong param type

Fix:

void AMyActor::SetHealth(float Value) { ... } // ✅ same type

✔️ 4. If Overriding a Function, Match Base Class Exactly

If you’re overriding a method from AActor or another base class, make sure the signature matches exactly, including override or virtual.

Fix:

virtual void Tick(float DeltaSeconds) override; // ✅ correct override

✅ Summary: How to Fix C2556 in UE5

CauseFix Example
Mismatched return typeMake sure .h and .cpp use the same return type
Missing or extra const keywordMatch method signature exactly in both declarations
Parameter type or count mismatchMatch number and types of arguments
Overriding base class methodMatch base method signature and use override if needed
Was this article helpful to you? Yes No

How can we help?