Among all things I’ve learned in C++ (which isn’t so much), operator overloading seems the most difficult. In general terms, when is it best to write an operator overload as a friend function? When do I have to explicilty use *this? Is always bad to use a temporary object?
Among all things I’ve learned in C++ (which isn’t so much), operator overloading seems
Share
Neil’s answer is correct. In addition, this link provides a lot of good information about when, where, why, and how to use the various types of operator overloading in C++.
In general, I’d try to stick with overloads that are intuitive — use of the ‘+’ operator should reflect something analogous to addition, etc. If you find yourself doing string comparisons with the ‘+’ operator or something like that, you should probably be using standard functions instead.