Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Operator overloading
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Rationale {{Anchor|Motive}}== Operator overloading is [[syntactic sugar]], and is used because it allows programming using notation nearer to the target domain<ref>{{cite web |website=C++ FAQ |title=Operator Overloading |url=https://isocpp.org/wiki/faq/operator-overloading#op-ov-benefits |last=Stroustrup |first=Bjarne |author-link=Bjarne Stroustrup |access-date=27 August 2020 |archive-url=https://web.archive.org/web/20110814105309/http://www.parashift.com/c++-faq-lite/operator-overloading.html#faq-13.2 |archive-date=14 August 2011}}</ref> and allows user-defined types a similar level of syntactic support as types built into a language. It is common, for example, in scientific computing, where it allows computing representations of mathematical objects to be manipulated with the same syntax as on paper. Operator overloading does not change the [[Expressive power (computer science)|expressive power]] of a language (with functions), as it can be emulated using function calls. For example, consider variables {{code|a}}, {{code|b}} and {{code|c}} of some user-defined type, such as [[Matrix (mathematics)|matrices]]: {{code|a + b * c}} In a language that supports operator overloading, and with the usual assumption that the {{code|*}} operator has higher [[Order of operations|precedence]] than the {{code|+}} operator, this is a concise way of writing: {{code|Add(a, Multiply(b, c))}} However, the former syntax reflects common mathematical usage.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)