3 ms·
Operator overloading is just a function call. Everything you say about overloading an operator could be said about the function call that would replace the ove
by SamReidHughes 12y ago
Operator overloading is just a function call. Everything you say about overloading an operator could be said about the function call that would replace the overloaded operator. I've never had trouble recognizing that a use of an operator was being done with a non-primitive type, which is the only way the confusion you describe could possibly happen, and the problem you describe has never happened to me while working on C++ code. I don't know why you think it is even plausible.
- Nursie 12y agoA function call is always a function call, an operator is not. It makes for more opaque code.
- SamReidHughes 12y agoFunction calls aren't always function calls.
- vardump 12y agoOperator overloading is a syntactic sugar trick that hides the real method call. Nothing more, nothing less. It's useful in vector math, complex number math, matrix math.
- TheCoelacanth 12y agoOperator overloading is useful for a lot more than just math. Overloading * and -> is useful for pointer-like types. Overloading () is useful for function-like types. Overloading [] is useful for collections and overloading ++ and -- is useful for iterators.
- SamReidHughes 12y agoThe overloading of (), [], and the like is used but it's not necessary. They could have been other named overloaded functions.