title: Unreal Engine C++ Error C4458: declaration of 'item' hides class member. What can I fix?
body: <p>I am pretty new to Unreal Engine and C++. I am creating an escape room in Unreal, but have come across error C4458 and am looking to see if anyone can help me see what I could do to fix it. Any help is appreciated!</p>
  <p>No errors are shown in Visual Studio, only in Unreal Engine Compiler Log. When I try to compile C++ scripts, this error is shown:</p>
  <p>Character_Controller.h(45): error C4458: declaration of 'item' hides class member
  Character_Controller.h(34): note: see declaration of 'FInventoryItem::item'</p>
  <p>This is the Character_Controller.h script:</p>
  <pre><code>    // Fill out your copyright notice in the Description page of Project Settings.
  
  #pragma once
  
  #include &quot;CoreMinimal.h&quot;
  #include &quot;Components/ActorComponent.h&quot;
  #include &quot;GameFramework/Actor.h&quot;
  #include &quot;GameFramework/Character.h&quot;
  #include &quot;Components/InputComponent.h&quot;
  #include &quot;Engine/DataTable.h&quot;
  #include &quot;Engine/World.h&quot;
  #include &quot;EscapeRoomGameModeBase.h&quot;
  #include &quot;Item.h&quot;
  #include &quot;Components/SphereComponent.h&quot;
  #include &quot;Character_Controller.generated.h&quot;
  
  USTRUCT(BlueprintType)
  struct FInventoryItem: public FTableRowBase
  {
      GENERATED_BODY()
  
  public:
  
      FInventoryItem()
      {
          name = FText::FromString(&quot;item&quot;);
          isVisible = false;
      }
  
      UPROPERTY(EditAnywhere, BlueprintReadWrite)
          FName itemId;
  
      UPROPERTY(EditAnywhere, BlueprintReadWrite)
          TSubclassOf&lt;class AItem&gt; item; &lt;--- LINE 34
  
      UPROPERTY(EditAnywhere, BlueprintReadWrite)
          FText name;
  
      UPROPERTY(EditAnywhere, BlueprintReadWrite)
          bool isVisible;
  
      UPROPERTY(EditAnywhere, BlueprintReadWrite)
          UTexture2D* image;
  
      bool operator==(const FInventoryItem&amp; item) const &lt;---- ERROR HERE
      {
          if (itemId == item.itemId)
              return true;
          else return false;
      }
  };
  
  UCLASS()
  class ESCAPEROOM_API ACharacter_Controller : public ACharacter
  {
      GENERATED_BODY()
  
  public:
      // Sets default values for this character's properties
      ACharacter_Controller();
  
  protected:
      // Called when the game starts or when spawned
      virtual void BeginPlay() override;
  
      UFUNCTION(BlueprintCallable, Category = &quot;Items&quot;)
          void Collect();
  
      UFUNCTION()
          void InventoryPlus();
  
      UFUNCTION()
          void InventoryMinus();
  
  public: 
      // Called every frame
      virtual void Tick(float DeltaTime) override;
  
      // Called to bind functionality to input
      virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
      void Horizontal_Movement(float axis);
      void Vertical_Movement(float axis);
  
      UFUNCTION(BlueprintCallable, Category = &quot;Utilities&quot;)
          void AddToInventory(FName id);
  
      UFUNCTION(BlueprintCallable, Category = &quot;Utilities&quot;)
          void RemoveFromInventory();
  
      UFUNCTION()
          void Wielding();
  
      UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
          TArray&lt;FInventoryItem&gt; inventory;
  
      UPROPERTY(EditAnywhere, BlueprintReadWrite)
          int inventoryI;
  
      UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = &quot;true&quot;))
          class USphereComponent* collectionRange;
  
      UPROPERTY(EditAnywhere, BlueprintReadWrite)
          FInventoryItem wield;
  
      UPROPERTY(EditAnywhere, BlueprintReadWrite)
          FInventoryItem empty;
  
      UPROPERTY(EditAnywhere, BlueprintReadWrite)
          TArray&lt;FInventoryItem&gt; pickupableObjects;
  
      UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = &quot;Wield Items&quot;)
          TArray&lt;AActor*&gt; wieldObjects;
  
      FORCEINLINE class USphereComponent* GetCollectionRange() const { return collectionRange; }
  
  
  };
  </code></pre>
  <p>Here is the Character_Controller.cpp script:</p>
  <pre><code>// Fill out your copyright notice in the Description page of Project Settings.
  
  
  #include &quot;Character_Controller.h&quot;
  
  // Sets default values
  ACharacter_Controller::ACharacter_Controller()
  {
      // Set this character to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
      PrimaryActorTick.bCanEverTick = true;
  
  
      inventoryI = 0;
      empty.itemId = &quot;0&quot;;
  
      collectionRange = CreateDefaultSubobject&lt;USphereComponent&gt;(TEXT(&quot;collectionRange&quot;));
      collectionRange-&gt;AttachToComponent(RootComponent, FAttachmentTransformRules(EAttachmentRule::SnapToTarget, true));
      collectionRange-&gt;AttachToComponent(RootComponent, FAttachmentTransformRules(EAttachmentRule::SnapToTarget, true));
      collectionRange-&gt;SetSphereRadius(100.0f);
  
  }
  
  // Called when the game starts or when spawned
  void ACharacter_Controller::BeginPlay()
  {
      Super::BeginPlay();
  
      for (int i = 0; i &lt; wieldObjects.Num(); i++)
      {
          if (wieldObjects[i])
          {
              wieldObjects[i]-&gt;SetActorHiddenInGame(true);
          }
      }
      
  }
  
  // Called every frame
  void ACharacter_Controller::Tick(float DeltaTime)
  {
      Super::Tick(DeltaTime);
  
  }
  
  // Called to bind functionality to input
  void ACharacter_Controller::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
  {
      Super::SetupPlayerInputComponent(PlayerInputComponent);
  
      InputComponent-&gt;BindAxis(&quot;MoveX&quot;, this, &amp;ACharacter_Controller::Vertical_Movement);
      InputComponent-&gt;BindAxis(&quot;MoveY&quot;, this, &amp;ACharacter_Controller::Horizontal_Movement);
  
      InputComponent-&gt;BindAxis(&quot;CameraSide&quot;, this, &amp;ACharacter_Controller::AddControllerYawInput);
      InputComponent-&gt;BindAxis(&quot;CameraUp&quot;, this, &amp;ACharacter_Controller::AddControllerPitchInput);
  
      InputComponent-&gt;BindAction(&quot;Interaction&quot;, IE_Pressed, this, &amp;ACharacter_Controller::Collect);
      InputComponent-&gt;BindAction(&quot;InteractionPlus&quot;, IE_Pressed, this, &amp;ACharacter_Controller::InventoryPlus);
      InputComponent-&gt;BindAction(&quot;InteractionMinus&quot;, IE_Pressed, this, &amp;ACharacter_Controller::InventoryMinus);
  }
  
  void ACharacter_Controller::Horizontal_Movement(float axis)
  {
      if (axis)
      {
          AddMovementInput(GetActorRightVector(), axis);
      }
  }
  
  void ACharacter_Controller::Vertical_Movement(float axis)
  {
      if (axis)
      {
          AddMovementInput(GetActorForwardVector(), axis);
      }
  }
  
  void ACharacter_Controller::Collect()
  {
      TArray&lt;AActor*&gt; collectedItems;
      collectionRange-&gt;GetOverlappingActors(collectedItems);
  
      for (int i = 0; i &lt; collectedItems.Num(); i++)
      {
          AItem* const testItem = Cast&lt;AItem&gt;(collectedItems[i]);
          if (testItem &amp;&amp; testItem-&gt;GetActive())
          {
              testItem-&gt;Touched();
              AddToInventory(testItem-&gt;itemID);
              testItem-&gt;SetActive(false);
          }
      }
  }
  
  void ACharacter_Controller::InventoryPlus()
  {
      inventoryI += 1;
      if (inventoryI &gt;= 5)
      {
          inventoryI = 0;
      }
      Wielding();
  }
  
  void ACharacter_Controller::InventoryMinus()
  {
      inventoryI -= 1;
      if (inventoryI &lt; 0)
      {
          inventoryI = 4;
      }
      Wielding();
  }
  
  void ACharacter_Controller::AddToInventory(FName id)
  {
      AEscapeRoomGameModeBase* gameMode = Cast&lt;AEscapeRoomGameModeBase&gt;(GetWorld()-&gt;GetAuthGameMode());
      UDataTable* itemTable = gameMode-&gt;GetItemsDB();
  
      if (gameMode)
      {
          if (itemTable)
          {
              FInventoryItem* itemAdded = itemTable-&gt;FindRow&lt;FInventoryItem&gt;(id, &quot;&quot;);
              if (itemAdded)
              {
                  inventory.Add(*itemAdded);
                  Wielding();
              }
          }
      }
  }
  
  void ACharacter_Controller::RemoveFromInventory()
  {
      if (inventory.Num() &gt; inventoryI)
      {
          inventory.RemoveAt(inventoryI);
          Wielding();
      }
  }
  
  void ACharacter_Controller::Wielding()
  {
      if (inventory.Num() &gt; inventoryI)
      {
          wield = inventory[inventoryI];
          if (&amp;wield)
          {
              FString wieldValue = wield.itemId.ToString();
              int wieldI = FCString::Atoi(*wieldValue);
              for (int i = 0; i &lt; pickupableObjects.Num(); i++)
              {
                  if (wield.itemId == pickupableObjects[i].itemId)
                  {
                      if (wieldObjects[wieldI - 1])
                      {
                          wieldObjects[wieldI - 1]-&gt;SetActorHiddenInGame(false);
                      }
                  }
  
                  else
                  {
                      if (wieldObjects[i])
                      {
                          wieldObjects[i]-&gt;SetActorHiddenInGame(true);
                      }
                  }
              }
          }
          else
          {
              wield = empty;
          }
  
          if (wield == empty)
          {
              for (int i = 0; i &lt; pickupableObjects.Num(); i++)
              {
                  wieldObjects[i]-&gt;SetActorHiddenInGame(true);
              }
          }
      }
  }
  </code></pre>