Something I never really brought up before until now; in my previous coding classes, I was taught to believe that comparing strings using the “==” operator wouldn’t actually work so I thought about using the function “.Equals(FString)” to compensate for that. I didn’t know “==” can still work with strings in C++;
Yup! == works as equals in C++
It actually depends on the specific implementation of ‘string’ that you’re using. FString will have done something here that is called ‘operator overloading’, where it ‘sees’ that you’re using the ‘==’ operator to compare two instances of an FString, and it will probably internally use something similar to ‘.Equals()’.
Operator overloading makes code a lot more readable, but can be quite complex to implement and also cause a lot of confusion if you don’t know when it’s there. If the simple ‘+’ operator actually does something different than add two things, it can get hairy quite quickly.
1 Like