C4458: declaration of “InitialLocation” hides class member

Hi I’m working with unreal engine, I created an actor class named Floater and im trying to use FVectors, but im getting these error C4458: declaration of “InitialLocation” hides class member

this is my header file code

#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Floater.generated.h"

    UCLASS()
    class FIRSTPROJECT_API AFloater : public AActor
    {
        GENERATED_BODY()
        
    public: 
        // Sets default values for this actor's properties
        AFloater();
    
        UPROPERTY(VisibleAnywhere, Category = "ActorMeshComponents")
        UStaticMeshComponent* StaticMesh;
    
        UPROPERTY(EditInstanceOnly, BlueprintReadWrite, Category = "FloaterVectors")
    
        FVector InitialLocation = FVector(0.0f);
    
    protected:
        // Called when the game starts or when spawned
        virtual void BeginPlay() override;
    
    public: 
        // Called every frame
        virtual void Tick(float DeltaTime) override;
    
    };

and this is my cpp code

#include "Floater.h"
// Sets default values
AFloater::AFloater()
{
    // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
    PrimaryActorTick.bCanEverTick = true;
    
    StaticMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("CustomStaticMesh"));
}

// Called when the game starts or when spawned
void AFloater::BeginPlay()
{
    Super::BeginPlay();
    FVector InitialLocation = FVector(0.0f, 0.0f, 0.0f); //img etting the error in this line of code
    SetActorLocation(InitialLocation);
}

// Called every frame
void AFloater::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);

}

im grtting error in BeginPlay() function FVector InitialLocation = FVector(0.0f, 0.0f, 0.0f);

please help resolve this C4458:declaration of “InitialLocation” hides class member

without removing the FVector InitialLocation variable

picture of the error

1 Like

That error usually happens when there is a base class variable with a similar name. When you redefine it C++ doesn’t know which one you are talking about. So try using another variable name for your variable InitialLocation.