x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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?
Product Version: Not Selected
Tags:
more ▼

asked Aug 09 '14 at 11:48 PM in C++ Programming

avatar image

dissonanceint
1k 42 28 65

avatar image Shadowriver Aug 10 '14 at 12:10 AM

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

avatar image Crefossus Feb 17 '17 at 01:00 AM

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

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

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

more ▼

answered Aug 10 '14 at 12:13 AM

avatar image

iniside
1.6k 102 96 181

avatar image dissonanceint Aug 10 '14 at 03:36 AM

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!

avatar image Edregol May 08 '15 at 07:52 PM

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?

avatar image Edregol May 10 '15 at 08:59 AM

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

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question