# Error when using a struct as the values in a TMap.

**URL:** <https://forums.unrealengine.com/t/error-when-using-a-struct-as-the-values-in-a-tmap/1200103>\
**Category:** C++\
**Tags:** unreal-engine, question\
**Created:** [June 15, 2023, 2:00pm UTC](https://forums.unrealengine.com/t/error-when-using-a-struct-as-the-values-in-a-tmap/1200103 "2023-06-15T14:00:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ViaCognita](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/viacognita/32/906601_2.png) [@ViaCognita](https://forums.unrealengine.com/u/ViaCognita)\
**Post date:** [June 15, 2023, 2:00pm UTC](https://forums.unrealengine.com/t/error-when-using-a-struct-as-the-values-in-a-tmap/1200103/1 "2023-06-15T14:00:14Z")

</div>

Hi!

I’m using Unreal Engine 5.2 with C++ and Visual Studio Enterprise 2022.

I have declared this `TMap`:

```auto
private:
	UPROPERTY()
	TMap<int32, FBall> BallMap;

```

The struct is:

```auto
USTRUCT(BlueprintType)
struct FBall
{
	GENERATED_BODY()

	int32 Hip;
	bool ABoolean;
	double DoubleValue1;
	double DoubleValue2;
	double Mag;
	FString StringValue1;
	FString StringValue2;
	FString StringValue3;
	double DoubleValue3;

	UPROPERTY()
	class ABallActor* BallActor = nullptr;

	FStruct1 StructureValue1;
	FVector ALocation;

	FStruct2 StructureValue2;
	double DoubleValue4;
};

```

When I add a new value to the `TMap`:

```auto
while (PreparedStatement->Step() == ESQLitePreparedStatementStepResult::Row)
{
	Fball ball;

	PreparedStatement->GetColumnValueByName(TEXT("HIP"), ball.Hip);
	[...]
	
	BallsMap.Add(ball.Hip, ball);
}

```

I get this error:

```auto
G:\Sources\Repos\MyProject\Unreal\MyProjectTest\Source\MyProject\Private\CatalogueGameInstanceSubsystem.cpp(353): error C2663: 'TMapBase<KeyType,ValueType,SetAllocator,KeyFuncs>::Add': no overloaded function has a valid cast for 'this' pointer
         with
         [
             KeyType=int32,
             ValueType=FBall,
             SetAllocator=FDefaultSetAllocator,
             KeyFuncs=TDefaultMapHashableKeyFuncs<int32,FBall,false>
         ]
G:\Games\Epic Games\UE_5.2\Engine\Source\Runtime\Core\Public\Containers\Map.h(365): note: can be 'ValueType &TMapBase<KeyType,ValueType,SetAllocator,KeyFuncs>::Add (KeyType &&,ValueType &&)'
         with
         [
             ValueType=FBall,
             KeyType=int32,
             SetAllocator=FDefaultSetAllocator,
             KeyFuncs=TDefaultMapHashableKeyFuncs<int32,FBall,false>
         ]
G:\Sources\Repos\MyProject\Unreal\MyProjectTest\Source\MyProject\Private\CatalogueGameInstanceSubsystem.cpp(353): note: 'ValueType &TMapBase<KeyType,ValueType,SetAllocator,KeyFuncs>::Add(KeyType &&,ValueT ype &&) ': cannot convert pointer 'this' from 'const TMap<int32,FBall,FDefaultSetAllocator,TDefaultMapHashableKeyFuncs<InKeyType,InValueType,false>>' to 'TMapBase<KeyType,ValueType,SetAllocator,KeyFuncs> &'
         with
         [
             ValueType=FBall,
             KeyType=int32,
             SetAllocator=FDefaultSetAllocator,
             KeyFuncs=TDefaultMapHashableKeyFuncs<int32,FBall,false>
         ]
         and
         [
             InKeyType=int32,
             InValueType=FBall
         ]
         and
         [
             KeyType=int32,
             ValueType=FBall,
             SetAllocator=FDefaultSetAllocator,
             KeyFuncs=TDefaultMapHashableKeyFuncs<int32,FBall,false>
         ]
G:\Sources\Repos\MyProject\Unreal\MyProjectTest\Source\MyProject\Private\CatalogueGameInstanceSubsystem.cpp(353): note: Lost qualifiers on conversion
G:\Games\Epic Games\UE_5.2\Engine\Source\Runtime\Core\Public\Containers\Map.h(364): note: o 'ValueType &TMapBase<KeyType,ValueType,SetAllocator,KeyFuncs>::Add( KeyType &&,const ValueType &)'
         with
         [
             ValueType=FBall,
             KeyType=int32,
             SetAllocator=FDefaultSetAllocator,
             KeyFuncs=TDefaultMapHashableKeyFuncs<int32,FBall,false>
         ]
G:\Sources\Repos\MyProject\Unreal\MyProjectTest\Source\MyProject\Private\CatalogueGameInstanceSubsystem.cpp(353): note: 'ValueType &TMapBase<KeyType,ValueType,SetAllocator,KeyFuncs>::Add(KeyType &&,const Value Type & )': Cannot convert pointer 'this' from 'const TMap<int32,FBall,FDefaultSetAllocator,TDefaultMapHashableKeyFuncs<InKeyType,InValueType,false>>' to 'TMapBase<KeyType,ValueType,SetAllocator,KeyFuncs> &'
         with
         [
             ValueType=FBall,
             KeyType=int32,
             SetAllocator=FDefaultSetAllocator,
             KeyFuncs=TDefaultMapHashableKeyFuncs<int32,FBall,false>
         ]
         and
         [
             InKeyType=int32,
             InValueType=FBall
         ]
         and
         [
             KeyType=int32,
             ValueType=FBall,
             SetAllocator=FDefaultSetAllocator,
             KeyFuncs=TDefaultMapHashableKeyFuncs<int32,FBall,false>
         ]
G:\Sources\Repos\MyProject\Unreal\MyProjectTest\Source\MyProject\Private\CatalogueGameInstanceSubsystem.cpp(353): note: Lost qualifiers on conversion
G:\Games\Epic Games\UE_5.2\Engine\Source\Runtime\Core\Public\Containers\Map.h(363): note: o 'ValueType &TMapBase<KeyType,ValueType,SetAllocator,KeyFuncs>::Add( const KeyType &,ValueType &&)'
         with
         [
             ValueType=FBall,
             KeyType=int32,
             SetAllocator=FDefaultSetAllocator,
             KeyFuncs=TDefaultMapHashableKeyFuncs<int32,FBall,false>
         ]
G:\Sources\Repos\MyProject\Unreal\MyProjectTest\Source\MyProject\Private\CatalogueGameInstanceSubsystem.cpp(353): note: 'ValueType &TMapBase<KeyType,ValueType,SetAllocator,KeyFuncs>::Add(const KeyType &,ValueT ype && )': Cannot convert pointer 'this' from 'const TMap<int32,FBall,FDefaultSetAllocator,TDefaultMapHashableKeyFuncs<InKeyType,InValueType,false>>' to 'TMapBase<KeyType,ValueType,SetAllocator,KeyFuncs> &'
         with
         [
             ValueType=FBall,
             KeyType=int32,
             SetAllocator=FDefaultSetAllocator,
             KeyFuncs=TDefaultMapHashableKeyFuncs<int32,FBall,false>
         ]
         and
         [
             InKeyType=int32,
             InValueType=FBall
         ]
         and
         [
             KeyType=int32,
             ValueType=FBall,
             SetAllocator=FDefaultSetAllocator,
             KeyFuncs=TDefaultMapHashableKeyFuncs<int32,FBall,false>
         ]
G:\Sources\Repos\MyProject\Unreal\MyProjectTest\Source\MyProject\Private\CatalogueGameInstanceSubsystem.cpp(353): note: Lost qualifiers on conversion
G:\Games\Epic Games\UE_5.2\Engine\Source\Runtime\Core\Public\Containers\Map.h(362): note:or 'ValueType &TMapBase<KeyType,ValueType,SetAllocator,KeyFuncs>::Add(const KeyType &,const ValueType &)'
         with
         [
             ValueType=FBall,
             KeyType=int32,
             SetAllocator=FDefaultSetAllocator,
             KeyFuncs=TDefaultMapHashableKeyFuncs<int32,FBall,false>
         ]
G:\Sources\Repos\MyProject\Unreal\MyProjectTest\Source\MyProject\Private\CatalogueGameInstanceSubsystem.cpp(353): note: 'ValueType &TMapBase<KeyType,ValueType,SetAllocator,KeyFuncs>::Add(const KeyType &,const Value type &)': Cannot convert pointer 'this' from 'const TMap<int32,FBall,FDefaultSetAllocator,TDefaultMapHashableKeyFuncs<InKeyType,InValueType,false>>' to 'TMapBase<KeyType,ValueType,SetAllocator,KeyFuncs> &'
         with
         [
             ValueType=FBall,
             KeyType=int32,
             SetAllocator=FDefaultSetAllocator,
             KeyFuncs=TDefaultMapHashableKeyFuncs<int32,FBall,false>
         ]
         and
         [
             InKeyType=int32,
             InValueType=FBall
         ]
         and
         [
             KeyType=int32,
             ValueType=FBall,
             SetAllocator=FDefaultSetAllocator,
             KeyFuncs=TDefaultMapHashableKeyFuncs<int32,FBall,false>
         ]
G:\Sources\Repos\MyProject\Unreal\MyProjectTest\Source\MyProject\Private\CatalogueGameInstanceSubsystem.cpp(353): note: Lost qualifiers on conversion
G:\Sources\Repos\MyProject\Unreal\MyProjectTest\Source\MyProject\Private\CatalogueGameInstanceSubsystem.cpp(353): note: when matching argument list '(int32, FBall)'

```

I don’t know how to solve it.

How can I fix this problem?

Thanks!

---

<div class="post-metadata">

**Author:** ![Chatouille](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/chatouille/32/1194622_2.png) [@Chatouille](https://forums.unrealengine.com/u/Chatouille)\
**Post date:** [June 15, 2023, 4:06pm UTC](https://forums.unrealengine.com/t/error-when-using-a-struct-as-the-values-in-a-tmap/1200103/2 "2023-06-15T16:06:43Z")

</div>

> [@ViaCognita](#):
>
> `BallsMap.Add(ball.Hip, ball);`

I don’t see Hip as a member of FBall.

Are you executing this code in a const member function by any chance ?

---

<div class="post-metadata">

**Author:** ![ViaCognita](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/viacognita/32/906601_2.png) [@ViaCognita](https://forums.unrealengine.com/u/ViaCognita)\
**Post date:** [June 15, 2023, 4:55pm UTC](https://forums.unrealengine.com/t/error-when-using-a-struct-as-the-values-in-a-tmap/1200103/3 "2023-06-15T16:55:36Z")

</div>

I’ve found the solution: the method is `const` and I’m modifying a member of the class.

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [July 15, 2023, 4:55pm UTC](https://forums.unrealengine.com/t/error-when-using-a-struct-as-the-values-in-a-tmap/1200103/4 "2023-07-15T16:55:52Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
