Declaration of 'InputComponent' hides class member

I have created the SetupPlayerInputComponent function exactly like the Unreal documentation shows it. I’ve followed a tutorial using it and written it exactly the same. Still this compilation error shows up every now and then.

The function is written in a C++ class based on Pawn.

In the header file, Tank.h, the declaration reads as follows, under public:

virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;

In the .cpp file, the function reads as follows:

void ATank::SetupPlayerInputComponent(class UInputComponent* InputComponent) // It is this line, in the Tank.cpp, that the compiler gives the error on

	InputComponent->BindAxis("Move_Tank", this, &ATank::MoveTank);
	InputComponent->BindAxis("Rotate_Tank", this, &ATank::RotateTank);
	InputComponent->BindAxis("Aim_Azimuth", this, &ATank::AimAzimuth);
	InputComponent->BindAxis("Aim_Elevation", this, &ATank::AimElevation);
	InputComponent->BindAction("Primary_Fire", IE_Pressed, this, &ATank::Fire);

I know this is a fairly common compilation error, but in this case I can’t for the life of me figure out why it’s occurring.
For the most part the error only occurs when any other compilation error occurs, and occasionally by itself when something is changed. But most of the time the compiler says nothing and everything works as intended.
Does anyone know what’s causing this sporadic error?

We are getting that also. Trying to fix it just to clean up the compile log. Doesn’t seem to cause problems.

Will report if I figure it out.

Looks like it is just because the variable InputComponent is the same as the class. So renaming it to “inputComponent” fixes the issue.

That’s correct. This was an oversight where the argument going into SetupInputComponent was named the same as a class variable, which caused the warning.

Changing the name of the argument in the SetupInputComponent function will fix the issue.

Change the parameter name fixed my problem too ! Thanks a lot!

No, that’s incorrect.
It has nothing to do with InputComponent function parameter being named the same as the class InputComponent.

For you the error “Declaration of ‘InputComponent’ hides class member” shows because you named function parameter “InputComponent” in your function
void ATank::SetupPlayerInputComponent(class UInputComponent InputComponent)* and you have member in your class also called InputComponent. So it’s named the same as a member in the class, not the same as the class.
Microsoft example explains it nicely: Compiler Warning (level 4) C4458 | Microsoft Docs

An easy fix is to rename your function parameter or class member from InputComponent to something else, like inputComponent. The problem with that is Visual Studio tells me that Unreal Engine’s naming convention is to have class members and function parameters, as well as even local variables inside functions to start with capital letter, so if you do that, that is a violation of their naming convention.

It’s not real hiding, you can still access the class member with the same name by doing this->InputComponent. The real hiding is when you create local variable with the same name in the inner block as in the outer block. That’s true hiding and you can’t access variable with the same name in the outer block from inside inner block after you declare the variable in the inner block with the same name.