If you get compile error C4458 with visual studio 2019

By default visual studio 2019 (not sure about other versions) waning level for compile is set to fail if a local variable could hide a class member as in the SteeringThrow class example

void AGoKart::ApplyRotation(float DeltaTime, float SteeringThrow)

{
	
	float DeltaLocation = FVector::DotProduct(GetActorForwardVector(), Velocity) * DeltaTime;
	float RotationAngle =  DeltaLocation / MinTurningRadius * SteeringThrow;

gives error

\Krazy_Karts\Source\Krazy_Karts\GoKart.cpp(132): error C4458: declaration of 'SteeringThrow' hides class member

Either rename the local variable in the constructor so it does not clash or you can disable the warning just for that class then reenable after using #pragma

the push stores the current warning state, then disables it then the pop resets the warning state to what it was.

I just changed the input var as I think it avoids confusion when reading the code later.

#pragma warning(push)
#pragma warning(disable: 4458)
void AGoKart::ApplyRotation(float DeltaTime, float SteeringThrow)

{
	
	float DeltaLocation = FVector::DotProduct(GetActorForwardVector(), Velocity) * DeltaTime;
	float RotationAngle =  DeltaLocation / MinTurningRadius * SteeringThrow;


	FQuat RotationDelta(GetActorUpVector(), RotationAngle);

	Velocity = RotationDelta.RotateVector(Velocity);


	AddActorWorldRotation(RotationDelta);

}
#pragma warning(pop)


1 Like

Thanks for the tip! Happy New Year :partying_face: