Operator= Overloading Already Declared?

My issue stems from accomidating the Swap( T& A, T& B ) method in UnrealTemplate.h so that I can take advantage of sorting a list of my UObject type. Otherwise the compiler complains that it “cannot access private member declared in class ___”. Which is odd, because all variables are public. I eventually chalked it up to probably being a complaint about the array. Here are the relevant data types.

UCLASS() class UIHLCM : public UObject {
GENERATED_UCLASS_BODY()

public:

int8 Priority;

int8 Step;

TArray<HLCMType> KillModifiers;

HLCMType Type;

}

I have already overloaded operator== but when I tried to overload the assignment operator in the following way, it complains that “error C2535: ‘UIHLCM &UIHLCM::operator =(const UIHLCM &)’ : member function already defined or declared”

FORCEINLINE UIHLCM& operator=(const UIHLCM &ihlcm) {
	Type = ihlcm.Type;
	
	// Other assignments go here

	return (*this);
}

If I’m overlooking something please let me know. I haven’t found any documentation anywhere expressing that I can’t do this.

I have been referring to this article:

EDIT: Resolved by sorting a list of pointers rather than objects.

Hi . If you were able to resolve the issue you were experiencing, would you mind posting what you did as an answer to this question? There may be others who are having the same issue, or a similar one, who would benefit from knowing how you were able to get it to work for you.

Thanks.

Update: I tracked the Swap() error down to the probable cause of either variables or methods in UObject not having explicitly defined privacy declarations. The solution was to change the list I was sorting to a list of pointers which can be freely remapped by the Swap() method. I am still unable to overload the assignment operator, but good news is that there are ways around it.

I had the same issue regarding assignment operators. It turns out that GENERATED_BODY() does only declare these operators, but does not implement them if they are present already.
My solution (which I haven’t tested thoroughly though) was to just implement the operators in the .cpp file, but not to declare them in the header.

1 Like

Yes,you are right!