TArray Find No operator found or suitable conversion

I created a custom struct called FItem. Then I declared an Array in my header:

TArray>FItem MyItems; (cant write the arrows here but they are done correctly in my code)

Then in my cpp

FItem Temp;

MyItems.Find(Temp);

And I get the following compile error:

Error 2 error C2678: binary ‘==’ : no operator found which takes a left-hand operand of type ‘const FItem’ (or there is no acceptable conversion)
Any ideas why this is happening?

It’s in the Find() method

Where do you use == operator? you dont have in code you pasted, check the line that error is pointing to, considering it’s ==, it’s most likely “if” condition

I assumie that FItem is custom data struct.

You need to overload == operator inside it. Find assumes there is operator == which will compare two values.

http://en.wikibooks.org/wiki/C%2B%2B_Programming/Operators/Operator_Overloading

Thank you VERY VERY VERY much! You didn’t only help me on this issue but made me realize the way to approach 2 or 3 problems I ran into earlier this week. Thanks!

Hi guys,

the same error occurs for me even though I have overwitten the == operator.

To visualise what I’ve done so far here are some code snippets:

I’ve defined the struct within its own .H file:

USTRUCT()
struct FInventoryItem
{
	GENERATED_USTRUCT_BODY()
	UPROPERTY()
	AActor* aItemActor;
	UPROPERTY()
	FText ftDescription;

	FInventoryItem()
	{
		aItemActor = NULL;
		ftDescription = NSLOCTEXT("test_english", "PickupText", "PickupText");
	}

	bool operator == (const FInventoryItem rhs)
	{
		if (aItemActor == rhs.aItemActor && ftDescription.EqualTo(rhs.ftDescription))
		{
			return true;
		}
		else return false;
	}
};

Within a saperate class header I’ve defined an array which contains these Items:

TArray<FInventoryItem> arrInventory; 

As soon as I call (within my .CPP):

arrInventory.Contains(AnotherFInventoryItem);

I get the compiler error :

binary '==' : no operator found which takes a left-hand operand of type 'const FInventoryItem' (or there is no acceptable conversion)

as well as:

could be 'bool FInventoryItem::operator ==(const FInventoryItem)' 
or 'bool operator ==(const FDialogueContextMapping &,const FDialogueContextMapping &)' 
or 'bool operator ==(const FDialogueContext &,const FDialogueContext &)'
...

So the compiler knows about my overwritten method but doesn’t use it. Any idea what I am missing?

Well obviously the parameters of the overwritten operator weren’t correct.
If I do it this way everything works just fine:
bool operator==( const FInventoryItemStruct& Other ) const

Other methods in TArray can call Find such as RemoveSingle. Just happened to me and google sent me here.

Yes dude, Thank you so much. Remove() was the problem in my case!

not working for me, i still get same error when i use .Contains() function in TArray, even if i write operator exac same way.