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"

right-hand operator overloading

I am receiving the error "binary '==': no operator found which takes a right-hand operand of type 'ABasicCharacter' (or there is no acceptable conversion)

I've tried all possibly ways I can think of to overload this operator, but have been unsuccessful. I assume I am misunderstanding something simple. Here is some simplified example code. Please ignore that the data it holds does not make sense as well as the function names.

The error occurs in the function "TestFunction"

This was originally working when my TArray was

 TArray<DataClass>* DataArray, 
 //but then I changed it to
  TArray<DataClass*>* DataArray
 //due to some changes in my coding.  (Pointer to TArray of objects   TO   Pointer to TArray of pointers)

 class ABasicCharacter
 {
 public:
     TArray<DataClass*>* DataArray;
     int UniqueCode;
 
     int GetUniqueCode_ABasicCharacterClass() const
     {
         return UniqueCode;
     }
 
     void TestFunction()
     {
         bool Outcome = DataArray->FindByKey(*this);
         //Error here, FindByKey is not recognizing my overloaded function.
     }
 };


 class DataClass
 {
 public:
     int UniqueCode;
 
     int GetUniqueCode_DataClass() const
     {
         return UniqueCode;
     }
 
     inline bool operator==(const ABasicCharacter& RHS) const
     {
         return this->GetUniqueCode_DataClass() == RHS.GetUniqueCode_ABasicCharacterClass();
     }
 };

Product Version: UE 4.21
Tags:
more ▼

asked Jul 12 '19 at 06:48 AM in C++ Programming

avatar image

Atijaf
5 2 3

avatar image HarryHighDef Jul 12 '19 at 09:26 AM

Is your DataClass a UClass? Have you considered making it a Struct/UStruct. Have you tried using the unreal FORCEINLINE macro instead of inline?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Hello,

friend bool operator==(const ABasicCharacter& RHS) { return this->GetUniqueCode_DataClass() == RHS.GetUniqueCode_ABasicCharacterClass(); }

Untested. Let me know in comment if it doesn't work.

more ▼

answered Jul 13 '19 at 07:02 PM

avatar image

Przemek2222
426 4 10 14

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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