Dis advantages and advantages of operator overloading in cpp
Answers
Answered by
1
There is no real downside to it other than losing short-circuiting on logical operators, at least in C++.
As long as it follows the expected behavior of the operator, overloads don't cause any problems. Operator overloading is just syntatic sugar for a function call. There is nothing magical about it. It just makes some code more idiomatic.
Done properly (by both the language and the programmer), it makes the language and your code more consistent, expressive and reusable.
Done inconsistently by the language, it adds unnecessary complications to the syntax and arbitrary constraints to the abstractions. A language should be entirely consistent in this or not do operator overloading at all.
Done badly by the developer, it can make code misleading and unpredictable.
As long as it follows the expected behavior of the operator, overloads don't cause any problems. Operator overloading is just syntatic sugar for a function call. There is nothing magical about it. It just makes some code more idiomatic.
Done properly (by both the language and the programmer), it makes the language and your code more consistent, expressive and reusable.
Done inconsistently by the language, it adds unnecessary complications to the syntax and arbitrary constraints to the abstractions. A language should be entirely consistent in this or not do operator overloading at all.
Done badly by the developer, it can make code misleading and unpredictable.
Similar questions
English,
8 months ago
Science,
8 months ago
History,
8 months ago
Computer Science,
1 year ago
Geography,
1 year ago