As always, the billboard summary is at the bottom. Now, the exact error (C2678) from your compiler:
This can occur with any custom structure and normally happens when you’ve attempted to use it as a key in a TMap or as the type for TArray. What it is essentially saying is that the compiler has no way of differentiating between two objects of that same type. Normally one can find this error when they haven’t included the ‘bool operator==’ of the error type (so operator> or operator< as well). A going-to-error-for-this-usecase structure definition would look like this:
In this instance we would need to include the bool operator function and a GetTypeHash() function like so:
But what if our structure is already defined with this and we still get an error?!
In this instance the error occurs because our definition of bool operator== is not static. For the use in TArray and TMap, the operator definition must be static.
Adding the ‘friend’ specifier to your bool operator will force the function to be static. Like so:
The compiler will automatically fill A and B when checking values of an array or map against one another to structure it correctly. So, the whole structure looks like this:
Duplicate your bool operator that is errored (whether operator==, <, or >) and add:
- the ‘friend’ specifier to make the function static
- ‘const FYourEpicStruct& VarName’ as the other to be checked against
like so: