Hello!
I have difficulties trying to use C++ 11 enum class feature in my current project.
This is the enum that I’ve created:
UENUM()
enum class WeaponID : uint8 {
Pistol,
Shotgun,
SniperRifle,
AssaultRifle
};
Problem #1:
When I declare this member variable in one of my classes:
TMap<WeaponID, AWeapon*> Weapons;
I get this:
F:\Epic Games\4.5\Engine\Source\Runtime\Core\Public\Containers\Map.h(158): error C2665: 'TSharedRef<ISlateMetaData,0>::GetTypeHash' : none of the 241 overloads could convert all the argument types
1> F:\Epic Games\4.5\Engine\Source\Runtime\Core\Public\Templates\SharedPointer.h(397): could be 'uint32 TSharedRef<ISlateMetaData,0>::GetTypeHash(const TSharedRef<ISlateMetaData,0> &)' [found using argument-dependent lookup]
1> F:\Epic Games\4.5\Engine\Source\Runtime\Core\Public\Templates\SharedPointer.h(397): or 'uint32 TSharedRef<FSlateWindowElementList::FDeferredPaint,0>::GetTypeHash(const TSharedRef<FSlateWindowElementList::FDeferredPaint,0> &)' [found using argument-dependent lookup]
1> f:\epic games\4.5\engine\source\runtime\core\public\uobject\WeakObjectPtrTemplates.h(178): or 'uint32 TWeakObjectPtr<ABrush,FWeakObjectPtr,FIndexToObject>::GetTypeHash(const TWeakObjectPtr<ABrush,FWeakObjectPtr,FIndexToObject> &)' [found using argument-dependent lookup]
1> F:\Epic Games\4.5\Engine\Source\Runtime\Core\Public\Containers\StaticArray.h(107): or 'uint32 TStaticArray<T,7,16>::GetTypeHash(const TStaticArray<T,7,16> &)' [found using argument-dependent lookup]
1> with
1> [
1> T=FVector4
1> ]
...
Once I replace WeaponID with uint8 in this line:
TMap<WeaponID, AWeapon*> Weapons;
the error goes away.
Why can’t I use my cutom enum as key in a TMap?
Problem #2
If I am trying to compile code containing this function:
UFUNCTION(Reliable, NetMulticast)
void SetActiveWeapon(WeaponID Weapon);
I get a bunch of these:
1>f:\\projects\gungame\ue4\trunk\merry\source\merry\MerryCharacter.h(23): error C3431: 'WeaponID' : a scoped enumeration cannot be redeclared as an unscoped enumeration
Does anyone know what is causing the problem?
Any advice would be highly appreciated!
Thanks!
.