Hi!
I’m using Unreal Engine 5.2 with C++ and Visual Studio Enterprise 2022.
I have declared this TMap
:
private:
UPROPERTY()
TMap<int32, FBall> BallMap;
The struct is:
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
:
while (PreparedStatement->Step() == ESQLitePreparedStatementStepResult::Row)
{
Fball ball;
PreparedStatement->GetColumnValueByName(TEXT("HIP"), ball.Hip);
[...]
BallsMap.Add(ball.Hip, ball);
}
I get this error:
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!