# How to overload operator == for (TArray)?

**URL:** <https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044>\
**Category:** C++\
**Tags:** UE4-20, unreal-engine, UE5-0, UE4, question, CPP\
**Created:** [August 24, 2022, 2:47am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044 "2022-08-24T02:47:23Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 24, 2022, 2:47am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/1 "2022-08-24T02:47:23Z")

</div>

Hi, I want to use `Array_Find` function in C++, so how i can overload the missing operator?  
I know it will need to rebuild the engine, so i have no other choice , i am ready to rebuild the engine so please help me

```auto
template<typename T, typename U>
	static int32 Array_Find(const TArray<T>& TargetArray, const U& ItemToFind)
	{
		return TargetArray.Find(ItemToFind);
	}

```

implementing this function gives an error.

```auto
int32 Index;
FTransform Location;
TArray<FTransform> TransformArray;
bool bEqualValid ;

Index = FCustomThunkTemplates::Array_Find(TransformArray, Location);

```

```auto
example:

Index = FCustomThunkTemplates::Array_Find(TransformArray, Location);
bEqualValid = UKismetMathLibrary::EqualEqual_IntInt(Index, -1);

```

## ERROR::

binary ‘==’: no operator found which takes a left-hand operand of type ‘const FTransform’ (or there is no acceptable conversion) **Containers\Array.h**

---

<div class="post-metadata">

**Author:** ![GigiK-K-K](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GigiK-K-K](https://forums.unrealengine.com/u/GigiK-K-K)\
**Post date:** [August 24, 2022, 7:16am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/2 "2022-08-24T07:16:30Z")

</div>

Still trying to fit an “int” into an “F transform”, I see.

If I were you I would return a float above directly in the return statement.

It’s the last line giving the error Location is an Ftransform type and you are trying to store it to Index that is an int. There is no engine error, you want to modify the engine so a int accepts a ftransform. Counting it’s a template type and you want to store the tepmlate to int.

I don’t know what is behind this

```auto
FCustomThunkTemplates::Array_Find

```

It might be that this makes a conversion possible, but I doubt it.

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 24, 2022, 7:21am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/3 "2022-08-24T07:21:10Z")

</div>

yes Sir i am still struggling with this, i can’t leave it without solving

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 24, 2022, 7:22am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/4 "2022-08-24T07:22:50Z")

</div>

this is find function, the Array\_Find is returning it.

````auto
SizeType Find(const ElementType& Item) const
	{
		const ElementType* RESTRICT Start = GetData();
		for (const ElementType* RESTRICT Data = Start, *RESTRICT DataEnd = Data + ArrayNum; Data != DataEnd; ++Data)
		{
			if (*Data == Item)
			{
				return static_cast<SizeType>(Data - Start);
			}
		}
		return INDEX_NONE;
	}```
````

---

<div class="post-metadata">

**Author:** ![GigiK-K-K](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GigiK-K-K](https://forums.unrealengine.com/u/GigiK-K-K)\
**Post date:** [August 24, 2022, 7:35am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/5 "2022-08-24T07:35:58Z")

</div>

It’s a strange for loop, I never seen it like this. " but you can tell that it’s counting with ++Data"  
It’s counting the variable Data and as in counts if it encounters something identical like in the Item it returns a static\_cast, or as I see at the end a range between Data and Start. There is no conversion elements here.

I don’t think there is anything wrong with this, your addition is wrong that you are trying to store it to int.

---

<div class="post-metadata">

**Author:** ![c0r37py](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/c0r37py/32/559700_2.png) [@c0r37py](https://forums.unrealengine.com/u/c0r37py)\
**Post date:** [August 24, 2022, 7:37am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/6 "2022-08-24T07:37:13Z")

</div>

Dont use `Array_Find` it works behind the scene on memory level for registered products instances, you can do it manually but it will have a huge risk of memory leak, I recommend to use `ContainsByPredicate` using `do|while` loop , but you can overload `==` and `!=` for int = t`ransfromArrayElements.find(TransformElement)`

* * *

hope it heps  
cheers!

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 24, 2022, 7:42am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/7 "2022-08-24T07:42:33Z")

</div>

Sir I don’t store it to int, I find the `Ftransform data` in `Ftransform Array variable` and then during this search of data between them I am sure there is an index which I am storing in `int`  
This `find` function is returning an integer

 ![l6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/3/1/731e93a9993d774e7c68867170914e11be256569.png)

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 24, 2022, 7:43am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/8 "2022-08-24T07:43:50Z")

</div>

Sir I am tired trying this do/while loop, it freezes the engine and i have to close it through visual studio clicking the stop button

---

<div class="post-metadata">

**Author:** ![c0r37py](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/c0r37py/32/559700_2.png) [@c0r37py](https://forums.unrealengine.com/u/c0r37py)\
**Post date:** [August 24, 2022, 7:44am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/9 "2022-08-24T07:44:41Z")

</div>

no way it can freez the engine, post your code, you are probably doing something wrong with the loop

---

<div class="post-metadata">

**Author:** ![GigiK-K-K](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GigiK-K-K](https://forums.unrealengine.com/u/GigiK-K-K)\
**Post date:** [August 24, 2022, 7:45am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/10 "2022-08-24T07:45:21Z")

</div>

> [@Alexa.Ki](#):
>
> `Index = FCustomThunkTemplates::Array_Find(TransformArray, Location);`

```auto
Index = FCustomThunkTemplates::Array_Find(TransformArray, Location);

```

Index is of type int, and you want to store the static call function with the paremeters inserted to int. This is a call on a function with parameters

---

<div class="post-metadata">

**Author:** ![GigiK-K-K](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GigiK-K-K](https://forums.unrealengine.com/u/GigiK-K-K)\
**Post date:** [August 24, 2022, 7:47am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/11 "2022-08-24T07:47:52Z")

</div>

What is that there

```auto
		return INDEX_NONE;

```

Is it placed by you there ?  
This is a hint that it does not return numerical whole indexes, exactly what you are doing.

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 24, 2022, 7:47am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/12 "2022-08-24T07:47:53Z")

</div>

I created the native code of this find function

 ![image_2022-08-24_124743408](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/4/f/64fa3e0eac9df61636a6c2278d76cc1381f5c7e6.png)

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 24, 2022, 7:49am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/13 "2022-08-24T07:49:19Z")

</div>

> [@c0r37py](#):
>
> no way it can freez the engine, post your code, you are probably doing something wrong with the loop

```auto
do
	{
		RandomLocation(Available, Location);
	} while (UsedLocations.ContainsByPredicate([Location](const FTransform Transform)
	{
		return Transform.GetLocation() == Location.GetLocation()
			&& Transform.GetRotation() == Location.GetRotation()
			&& Transform.GetScale3D() == Location.GetScale3D();
	}));
	SpawnLocation = Location;
	UsedLocations.Add(SpawnLocation);

```

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 24, 2022, 7:50am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/14 "2022-08-24T07:50:08Z")

</div>

no, not by me, its already in the file

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 24, 2022, 7:50am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/15 "2022-08-24T07:50:43Z")

</div>

> [@GigiK-K-K](#):
>
> Is it placed by you there ?

its already in the file, not by me

---

<div class="post-metadata">

**Author:** ![c0r37py](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/c0r37py/32/559700_2.png) [@c0r37py](https://forums.unrealengine.com/u/c0r37py)\
**Post date:** [August 24, 2022, 7:51am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/16 "2022-08-24T07:51:44Z")

</div>

what I can see is your loop is infinite and you are doing this on the reverse direction 🤣

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 24, 2022, 7:53am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/17 "2022-08-24T07:53:33Z")

</div>

Sir I am confused, can you please fix it so I can se what was wrong 😫

---

<div class="post-metadata">

**Author:** ![GigiK-K-K](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GigiK-K-K](https://forums.unrealengine.com/u/GigiK-K-K)\
**Post date:** [August 24, 2022, 7:59am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/18 "2022-08-24T07:59:55Z")

</div>

> [@Alexa.Ki](#):
>
> `FCustomThunkTemplates::Array_Find`

Well the error is clear, it refers to conversions from one type to other type.  
no operator found which takes a left-hand operand of type ‘const FTransform’

1  
So it’s a type FTransform that you are fiting inside “Index”  
This is the actual error and because of this you got an error with type Ftransform.

2  
You are putting an FTransform as a parameter on a function call and maybe that function does not contain an Ftransform there for you are trying to convert a parameter to Ftransfrom

It’s either one or two, or maybe bolth.

Tell me here, where do you see an Ftransfrom type here

````auto
SizeType Find(const ElementType& Item) const
	{
		const ElementType* RESTRICT Start = GetData();
		for (const ElementType* RESTRICT Data = Start, *RESTRICT DataEnd = Data + ArrayNum; Data != DataEnd; ++Data)
		{
			if (*Data == Item)
			{
				return static_cast<SizeType>(Data - Start);
			}
		}
		return INDEX_NONE;
	}```

````

The types here are not of Ftrasnfrom ? nor floats ?  
Yet you put an Ftransform as a type inside the parameter of the function call.

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 24, 2022, 8:03am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/19 "2022-08-24T08:03:15Z")

</div>

I don’t see it , you are right 🙂

---

<div class="post-metadata">

**Author:** ![c0r37py](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/c0r37py/32/559700_2.png) [@c0r37py](https://forums.unrealengine.com/u/c0r37py)\
**Post date:** [August 24, 2022, 8:08am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/20 "2022-08-24T08:08:20Z")

</div>

Fist you need to have a condition setter the loop will follow when to stop and continue.  
lets take a bool value `false/true`.

## myclass.cpp

```auto
do
	{
		SpawnLocation = Location;
		UsedLocations.Add(SpawnLocation);
	    break;
	} 
	while (UsedLocations.ContainsByPredicate([Location](const FTransform Transform)
	{
		return Transform.GetLocation() == Location.GetLocation();
	}));
		RandomLocation(Available, Location); //do this if the locations are not unique

```

hope it helps, cheers!

[Next page](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044.md?page=2)
