I have been Googling for a few hours now and came up with this so far but its still not working. It may be something to do with the pointers as I am still learning C++.
//Photo.h
public:
FORCEINLINE bool operator==(UPhoto &Other);
//Photo.cpp
bool UPhoto::operator==(UPhoto & Other)
{
UE_LOG(LogTemp, Warning, TEXT("OPERATOR OVERLOADED!")); // I never see this!!
return ((PhotoGrade == Other.PhotoGrade) && (PhotoSubject == Other.PhotoSubject));
}
//MyGameState.cpp
//create temp array with removed duplicates
TArray<UPhoto*> PhotosToAdd; //To add to master collection later
for(UPhoto* p : RunPhotos)
{
if (!PhotosToAdd.Contains(p)) //should be using overloaded == but always returns false
{
PhotosToAdd.Add(p);
}
}
Thanks for the reply Bruno but this is exactly what I had in the first place… the separating out was a last ditch effort before posting here. I have put it back to the way you mention above and it is still not working. At least I am not getting the UE_LOG readout at all.
I have even tried directly testing (p == p) which quite rightly returns true but it does not use my overloading. Am I missing something else fundamental required for operator overloading?
Thanks Zeblote, I am still working on that but I am currently more concerned that its not even trying to use my Overloaded operator. I am aware of some logical issues with this.
: )
[edit] unless you mean that is the reason for it not using my == operator?
So I am still stuck on this, I can’t get the Contains() to use my == operator because its an array of pointers. Even if I use dereferencing it does not work. I have tried writing my own method for comparing Arrays but keep getting choked by not being able to resize an array inside a for loop.
I have written and rewritten various methods but all either don’t work because I’m using pointers or I go round in circles until I end up trying to resize an array inside a for loop again. So frustrating… what is the work around to this?