# Operator= Overloading Already Declared?

**URL:** <https://forums.unrealengine.com/t/operator-overloading-already-declared/283024>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [May 10, 2014, 9:27pm UTC](https://forums.unrealengine.com/t/operator-overloading-already-declared/283024 "2014-05-10T21:27:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattuyw](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mattuyw](https://forums.unrealengine.com/u/mattuyw)\
**Post date:** [May 10, 2014, 9:27pm UTC](https://forums.unrealengine.com/t/operator-overloading-already-declared/283024/1 "2014-05-10T21:27:36Z")

</div>

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:

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

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

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_b666e59e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b666e59e](https://forums.unrealengine.com/u/anonymous_user_b666e59e)\
**Post date:** [May 12, 2014, 11:51pm UTC](https://forums.unrealengine.com/t/operator-overloading-already-declared/283024/2 "2014-05-12T23:51:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mattuyw](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mattuyw](https://forums.unrealengine.com/u/mattuyw)\
**Post date:** [May 13, 2014, 12:00am UTC](https://forums.unrealengine.com/t/operator-overloading-already-declared/283024/3 "2014-05-13T00:00:06Z")

</div>

**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.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_4b24d331](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4b24d331](https://forums.unrealengine.com/u/anonymous_user_4b24d331)\
**Post date:** [November 18, 2016, 5:01pm UTC](https://forums.unrealengine.com/t/operator-overloading-already-declared/283024/4 "2016-11-18T17:01:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![a409197988](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@a409197988](https://forums.unrealengine.com/u/a409197988)\
**Post date:** [December 25, 2018, 3:43am UTC](https://forums.unrealengine.com/t/operator-overloading-already-declared/283024/5 "2018-12-25T03:43:20Z")

</div>

Yes，you are right!
