<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://debianws.lexgopc.com/wiki143/index.php?action=history&amp;feed=atom&amp;title=Operator_overloading</id>
	<title>Operator overloading - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://debianws.lexgopc.com/wiki143/index.php?action=history&amp;feed=atom&amp;title=Operator_overloading"/>
	<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Operator_overloading&amp;action=history"/>
	<updated>2026-05-05T01:45:01Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>http://debianws.lexgopc.com/wiki143/index.php?title=Operator_overloading&amp;diff=4325309&amp;oldid=prev</id>
		<title>imported&gt;Amberkitten: Added tags to criticism section</title>
		<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Operator_overloading&amp;diff=4325309&amp;oldid=prev"/>
		<updated>2025-12-07T19:14:26Z</updated>

		<summary type="html">&lt;p&gt;Added tags to criticism section&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Previous revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 19:14, 7 December 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l109&quot;&gt;Line 109:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 109:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Criticisms==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Criticisms==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Operator overloading has often been criticized&amp;lt;ref&amp;gt;{{cite web |url=http://pages.cs.wisc.edu/~fischer/cs538.s08/lectures/Lecture08.4up.pdf |title=Issues in Overloading |last=Fisher |first=Charles N. |publisher=[[University of Wisconsin–Madison]] |year=2008}}&amp;lt;/ref&amp;gt; because it allows programmers to reassign the semantics of operators depending on the types of their operands. For example, the use of the {{code|&amp;lt;&amp;lt;}} operator in [[C++]] &amp;lt;syntaxhighlight lang=Cpp inline&amp;gt;a &amp;lt;&amp;lt; b&amp;lt;/syntaxhighlight&amp;gt; shifts the bits in the variable {{code|a}} left by {{code|b}} bits if {{code|a}} and {{code|b}} are of an integer type, but if {{code|a}} is an output stream then the above code will attempt to write a {{code|b}} to the stream. Because operator overloading allows the original programmer to change the usual semantics of an operator and to catch any subsequent programmers by surprise, it is considered good practice to use operator overloading with care (the creators of [[Java (programming language)|Java]] decided not to use this feature,&amp;lt;ref&amp;gt;{{cite web |url=http://www.oracle.com/technetwork/java/simple-142616.html#4098 |website=The Java Language Environment |title=No more operator overloading |publisher=[[Oracle Corporation]]}}&amp;lt;/ref&amp;gt; although not necessarily for this reason).&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Operator overloading has often been criticized&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;{{Weasel inline|date=December 2025}}&lt;/ins&gt;&amp;lt;ref&amp;gt;{{cite web |url=http://pages.cs.wisc.edu/~fischer/cs538.s08/lectures/Lecture08.4up.pdf |title=Issues in Overloading |last=Fisher |first=Charles N. |publisher=[[University of Wisconsin–Madison]] |year=2008}}&amp;lt;/ref&amp;gt; because it allows programmers to reassign the semantics of operators depending on the types of their operands. For example, the use of the {{code|&amp;lt;&amp;lt;}} operator in [[C++]] &amp;lt;syntaxhighlight lang=Cpp inline&amp;gt;a &amp;lt;&amp;lt; b&amp;lt;/syntaxhighlight&amp;gt; shifts the bits in the variable {{code|a}} left by {{code|b}} bits if {{code|a}} and {{code|b}} are of an integer type, but if {{code|a}} is an output stream then the above code will attempt to write a {{code|b}} to the stream. Because operator overloading allows the original programmer to change the usual semantics of an operator and to catch any subsequent programmers by surprise, it is considered good practice to use operator overloading with care (the creators of [[Java (programming language)|Java]] decided not to use this feature,&amp;lt;ref&amp;gt;{{cite web |url=http://www.oracle.com/technetwork/java/simple-142616.html#4098 |website=The Java Language Environment |title=No more operator overloading |publisher=[[Oracle Corporation]]}}&amp;lt;/ref&amp;gt; although not necessarily for this reason&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;{{Original research inline|date=December 2025}}&lt;/ins&gt;).&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Another, more subtle, issue with operators is that certain rules from mathematics can be wrongly expected or unintentionally assumed. For example, the [[Commutative property|commutativity]] of + (i.e. that {{code|1=a + b == b + a}}) does not always apply; an example of this occurs when the operands are strings, since + is commonly overloaded to perform a concatenation of strings (i.e. {{code|&amp;quot;bird&amp;quot; + &amp;quot;song&amp;quot;}} yields {{code|&amp;quot;birdsong&amp;quot;}}, while {{code|&amp;quot;song&amp;quot; + &amp;quot;bird&amp;quot;}} yields {{code|&amp;quot;songbird&amp;quot;}}). A typical counter{{citation needed|date=September 2013}} to this argument comes directly from mathematics: While + is commutative on integers (and more generally any complex number), it is not commutative for other &amp;quot;types&amp;quot; of variables. In practice, + is not even always [[operator associativity|associative]], for example with floating-point values due to rounding errors. Another example: In mathematics, multiplication is commutative for real and complex numbers but not commutative in [[matrix multiplication]].&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Another, more subtle, issue with operators is that certain rules from mathematics can be wrongly expected or unintentionally assumed. For example, the [[Commutative property|commutativity]] of + (i.e. that {{code|1=a + b == b + a}}) does not always apply; an example of this occurs when the operands are strings, since + is commonly overloaded to perform a concatenation of strings (i.e. {{code|&amp;quot;bird&amp;quot; + &amp;quot;song&amp;quot;}} yields {{code|&amp;quot;birdsong&amp;quot;}}, while {{code|&amp;quot;song&amp;quot; + &amp;quot;bird&amp;quot;}} yields {{code|&amp;quot;songbird&amp;quot;}}). A typical counter{{citation needed|date=September 2013}} to this argument comes directly from mathematics: While + is commutative on integers (and more generally any complex number), it is not commutative for other &amp;quot;types&amp;quot; of variables. In practice, + is not even always [[operator associativity|associative]], for example with floating-point values due to rounding errors. Another example: In mathematics, multiplication is commutative for real and complex numbers but not commutative in [[matrix multiplication]].&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l163&quot;&gt;Line 163:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 163:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;*[[MATLAB]]&amp;lt;ref&amp;gt;{{cite web |title=Implementing Operators for Your Class |url=http://www.mathworks.com/help/matlab/matlab_oop/implementing-operators-for-your-class.html |access-date=1 October 2013 |archive-date=14 June 2024 |archive-url=https://web.archive.org/web/20240614070735/https://www.mathworks.com/help/matlab/matlab_oop/implementing-operators-for-your-class.html |url-status=dead }}&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;*[[MATLAB]]&amp;lt;ref&amp;gt;{{cite web |title=Implementing Operators for Your Class |url=http://www.mathworks.com/help/matlab/matlab_oop/implementing-operators-for-your-class.html |access-date=1 October 2013 |archive-date=14 June 2024 |archive-url=https://web.archive.org/web/20240614070735/https://www.mathworks.com/help/matlab/matlab_oop/implementing-operators-for-your-class.html |url-status=dead }}&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;*[[Object Pascal]] ([[Free Pascal]],&amp;lt;ref&amp;gt;{{cite web |title=Operator Overloading |website=Free Pascal Manual |url=http://www.freepascal.org/docs-html/ref/refch15.html |access-date=1 December 2014}}&amp;lt;/ref&amp;gt; [[Delphi (programming language)|Delphi]] (since 2005)&amp;lt;ref&amp;gt;{{cite web |title=Operator Overloading |website=Delphi Manual |url=http://docwiki.embarcadero.com/RADStudio/XE4/en/Operator_Overloading_%28Delphi%29 |access-date=1 December 2014}}&amp;lt;/ref&amp;gt;)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;*[[Object Pascal]] ([[Free Pascal]],&amp;lt;ref&amp;gt;{{cite web |title=Operator Overloading |website=Free Pascal Manual |url=http://www.freepascal.org/docs-html/ref/refch15.html |access-date=1 December 2014}}&amp;lt;/ref&amp;gt; [[Delphi (programming language)|Delphi]] (since 2005)&amp;lt;ref&amp;gt;{{cite web |title=Operator Overloading |website=Delphi Manual |url=http://docwiki.embarcadero.com/RADStudio/XE4/en/Operator_Overloading_%28Delphi%29 |access-date=1 December 2014}}&amp;lt;/ref&amp;gt;)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;*[[PHP]] &amp;lt;ref&amp;gt;{{cite web |title=PHP magic methods overriding class properties |url=http://webwidetutor.com/php/php-oop-Magic-Methods-tutorial-?id=30 |access-date=7 April 2015 |archive-url=https://web.archive.org/web/20160304050243/http://webwidetutor.com/php/php-oop-Magic-Methods-tutorial-?id=30 |archive-date=4 March 2016}}&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;*[[PHP]]&amp;lt;ref&amp;gt;{{cite web |title=PHP magic methods overriding class properties |url=http://webwidetutor.com/php/php-oop-Magic-Methods-tutorial-?id=30 |access-date=7 April 2015 |archive-url=https://web.archive.org/web/20160304050243/http://webwidetutor.com/php/php-oop-Magic-Methods-tutorial-?id=30 |archive-date=4 March 2016}}&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;*[[Perl]]&amp;lt;ref name=&amp;quot;Orwant2002&amp;quot;&amp;gt;{{cite book |last=Orwant |first=Jon |title=Computer Science &amp;amp; Perl Programming: Best of The Perl Journal |url=https://books.google.com/books?id=8TkEOyBHoOoC&amp;amp;q=%22operator+overloading%22&amp;amp;pg=PA347 |date=4 November 2002 |publisher=O&amp;#039;Reilly Media, Inc. |isbn=978-0-596-00310-4 |pages=347–}}&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;*[[Perl]]&amp;lt;ref name=&amp;quot;Orwant2002&amp;quot;&amp;gt;{{cite book |last=Orwant |first=Jon |title=Computer Science &amp;amp; Perl Programming: Best of The Perl Journal |url=https://books.google.com/books?id=8TkEOyBHoOoC&amp;amp;q=%22operator+overloading%22&amp;amp;pg=PA347 |date=4 November 2002 |publisher=O&amp;#039;Reilly Media, Inc. |isbn=978-0-596-00310-4 |pages=347–}}&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;*[[Python (programming language)|Python]]&amp;lt;ref&amp;gt;{{cite web |url=https://docs.python.org/3/reference/datamodel.html |website=The Python Language Reference |title=3. Data Model}}&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;*[[Python (programming language)|Python]]&amp;lt;ref&amp;gt;{{cite web |url=https://docs.python.org/3/reference/datamodel.html |website=The Python Language Reference |title=3. Data Model}}&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l234&quot;&gt;Line 234:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 234:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Since &amp;quot;multi&amp;quot; was used, the function gets added to the list of [[multidispatch]] candidates, and &amp;quot;&amp;lt;code&amp;gt;+&amp;lt;/code&amp;gt;&amp;quot; is only overloaded for the case where the type constraints in the function signature are met.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Since &amp;quot;multi&amp;quot; was used, the function gets added to the list of [[multidispatch]] candidates, and &amp;quot;&amp;lt;code&amp;gt;+&amp;lt;/code&amp;gt;&amp;quot; is only overloaded for the case where the type constraints in the function signature are met.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;While the capacity for overloading includes &amp;lt;code&amp;gt;+&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;&amp;gt;=&amp;lt;/code&amp;gt;, the [[Imaginary unit|postfix and term &amp;lt;code&amp;gt;i&amp;lt;/code&amp;gt;]], and so on, it also allows for overloading various brace operators: &amp;lt;code&amp;gt;[x, y]&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;x[y]&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;x{y}&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;x(y)&amp;lt;/code&amp;gt;.  &lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;While the capacity for overloading includes &amp;lt;code&amp;gt;+&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;&amp;gt;=&amp;lt;/code&amp;gt;, the [[Imaginary unit|postfix and term &amp;lt;code&amp;gt;i&amp;lt;/code&amp;gt;]], and so on, it also allows for overloading various brace operators: &amp;lt;code&amp;gt;[x, y]&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;x[y]&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;x{y}&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;x(y)&amp;lt;/code&amp;gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Kotlin (programming language)|Kotlin]] has supported operator overloading since its creation by overwriting specially named functions (like &amp;lt;code&amp;gt;plus()&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;inc()&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;rangeTo()&amp;lt;/code&amp;gt;, etc.)&amp;lt;ref&amp;gt;{{Cite web|title=Operator overloading Kotlin|url=https://kotlinlang.org/docs/operator-overloading.html|website=kotlinlang.org|publisher=JetBrains s.r.o.|access-date=15 October 2025}}&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Kotlin (programming language)|Kotlin]] has supported operator overloading since its creation by overwriting specially named functions (like &amp;lt;code&amp;gt;plus()&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;inc()&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;rangeTo()&amp;lt;/code&amp;gt;, etc.)&amp;lt;ref&amp;gt;{{Cite web|title=Operator overloading Kotlin|url=https://kotlinlang.org/docs/operator-overloading.html|website=kotlinlang.org|publisher=JetBrains s.r.o.|access-date=15 October 2025}}&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>imported&gt;Amberkitten</name></author>
	</entry>
	<entry>
		<id>http://debianws.lexgopc.com/wiki143/index.php?title=Operator_overloading&amp;diff=3130837&amp;oldid=prev</id>
		<title>imported&gt;Derek farn: Shorten long list to more well known languages</title>
		<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Operator_overloading&amp;diff=3130837&amp;oldid=prev"/>
		<updated>2025-11-16T01:53:08Z</updated>

		<summary type="html">&lt;p&gt;Shorten long list to more well known languages&lt;/p&gt;
&lt;a href=&quot;http://debianws.lexgopc.com/wiki143/index.php?title=Operator_overloading&amp;amp;diff=3130837&amp;amp;oldid=14848&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>imported&gt;Derek farn</name></author>
	</entry>
	<entry>
		<id>http://debianws.lexgopc.com/wiki143/index.php?title=Operator_overloading&amp;diff=14848&amp;oldid=prev</id>
		<title>imported&gt;Adius: Add Julia to operator overloading table</title>
		<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Operator_overloading&amp;diff=14848&amp;oldid=prev"/>
		<updated>2025-03-14T11:08:23Z</updated>

		<summary type="html">&lt;p&gt;Add Julia to operator overloading table&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Short description|Feature of some programming languages}}&lt;br /&gt;
{{Use American English|date = March 2019}}&lt;br /&gt;
{{Use dmy dates|date=January 2021}}&lt;br /&gt;
{{Polymorphism}}&lt;br /&gt;
In [[computer programming]], &amp;#039;&amp;#039;&amp;#039;operator overloading&amp;#039;&amp;#039;&amp;#039;, sometimes termed &amp;#039;&amp;#039;operator [[ad hoc polymorphism]]&amp;#039;&amp;#039;, is a specific case of [[polymorphism (computer science)|polymorphism]], where different [[Operator (computer programming)|operators]] have different implementations depending on their arguments. Operator overloading is generally defined by a [[programming language]], a [[programmer]], or both.&lt;br /&gt;
&lt;br /&gt;
==Rationale {{Anchor|Motive}}==&lt;br /&gt;
Operator overloading is [[syntactic sugar]], and is used because it allows programming using notation nearer to the target domain&amp;lt;ref&amp;gt;{{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}}&amp;lt;/ref&amp;gt; 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.&lt;br /&gt;
&lt;br /&gt;
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]]:&lt;br /&gt;
&lt;br /&gt;
{{code|a + b * c}}&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
{{code|Add(a, Multiply(b, c))}}&lt;br /&gt;
&lt;br /&gt;
However, the former syntax reflects common mathematical usage.&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
In this case, the addition operator is overloaded to allow addition on a user-defined type {{code|Time}} in [[C++]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=Cpp&amp;gt;&lt;br /&gt;
Time operator+(const Time&amp;amp; lhs, const Time&amp;amp; rhs) {&lt;br /&gt;
  Time temp = lhs;&lt;br /&gt;
  temp.seconds += rhs.seconds;&lt;br /&gt;
  temp.minutes += temp.seconds / 60;&lt;br /&gt;
  temp.seconds %= 60;&lt;br /&gt;
  temp.minutes += rhs.minutes;&lt;br /&gt;
  temp.hours += temp.minutes / 60;&lt;br /&gt;
  temp.minutes %= 60;&lt;br /&gt;
  temp.hours += rhs.hours;&lt;br /&gt;
  return temp;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Addition is a [[binary operation]], which means it has two [[operand]]s. In C++, the arguments being passed are the operands, and the {{code|temp}} object is the returned value.&lt;br /&gt;
&lt;br /&gt;
The operation could also be defined as a class method, replacing {{code|lhs}} by the hidden {{code|this}} argument; However, this forces the left operand to be of type {{code|Time}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=Cpp&amp;gt;&lt;br /&gt;
// The &amp;quot;const&amp;quot; right before the opening curly brace means that |this| is not modified.&lt;br /&gt;
Time Time::operator+(const Time&amp;amp; rhs) const {&lt;br /&gt;
  Time temp = *this;  // |this| should not be modified, so make a copy.&lt;br /&gt;
  temp.seconds += rhs.seconds;&lt;br /&gt;
  temp.minutes += temp.seconds / 60;&lt;br /&gt;
  temp.seconds %= 60;&lt;br /&gt;
  temp.minutes += rhs.minutes;&lt;br /&gt;
  temp.hours += temp.minutes / 60;&lt;br /&gt;
  temp.minutes %= 60;&lt;br /&gt;
  temp.hours += rhs.hours;&lt;br /&gt;
  return temp;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that a [[Unary operation|unary]] operator defined as a class method would receive no apparent argument (it only works from {{code|this}}):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=Cpp&amp;gt;&lt;br /&gt;
bool Time::operator!() const {&lt;br /&gt;
  return hours == 0 &amp;amp;&amp;amp; minutes == 0 &amp;amp;&amp;amp; seconds == 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The less-than (&amp;lt;) operator is often overloaded to sort a structure or class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=Cpp&amp;gt;&lt;br /&gt;
class Pair {&lt;br /&gt;
 public:&lt;br /&gt;
  bool operator&amp;lt;(const Pair&amp;amp; p) const {&lt;br /&gt;
    if (x_ == p.x_) {&lt;br /&gt;
      return y_ &amp;lt; p.y_;&lt;br /&gt;
    }&lt;br /&gt;
    return x_ &amp;lt; p.x_;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
 private:&lt;br /&gt;
  int x_;&lt;br /&gt;
  int y_;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Like with the previous examples, in the last example operator overloading is done within the class. In C++, after overloading the less-than operator (&amp;lt;), [[sort (C++)|standard sorting functions]] can be used to sort some classes.&lt;br /&gt;
&lt;br /&gt;
==Criticisms==&lt;br /&gt;
Operator overloading has often been criticized&amp;lt;ref&amp;gt;{{cite web |url=http://pages.cs.wisc.edu/~fischer/cs538.s08/lectures/Lecture08.4up.pdf |title=Issues in Overloading |last=Fisher |first=Charles N. |publisher=[[University of Wisconsin–Madison]] |year=2008}}&amp;lt;/ref&amp;gt; because it allows programmers to reassign the semantics of operators depending on the types of their operands. For example, the use of the {{code|&amp;lt;&amp;lt;}} operator in [[C++]] &amp;lt;syntaxhighlight lang=Cpp inline&amp;gt;a &amp;lt;&amp;lt; b&amp;lt;/syntaxhighlight&amp;gt; shifts the bits in the variable {{code|a}} left by {{code|b}} bits if {{code|a}} and {{code|b}} are of an integer type, but if {{code|a}} is an output stream then the above code will attempt to write a {{code|b}} to the stream. Because operator overloading allows the original programmer to change the usual semantics of an operator and to catch any subsequent programmers by surprise, it is considered good practice to use operator overloading with care (the creators of [[Java (programming language)|Java]] decided not to use this feature,&amp;lt;ref&amp;gt;{{cite web |url=http://www.oracle.com/technetwork/java/simple-142616.html#4098 |website=The Java Language Environment |title=No more operator overloading |publisher=[[Oracle Corporation]]}}&amp;lt;/ref&amp;gt; although not necessarily for this reason).&lt;br /&gt;
&lt;br /&gt;
Another, more subtle, issue with operators is that certain rules from mathematics can be wrongly expected or unintentionally assumed. For example, the [[Commutative property|commutativity]] of + (i.e. that {{code|1=a + b == b + a}}) does not always apply; an example of this occurs when the operands are strings, since + is commonly overloaded to perform a concatenation of strings (i.e. {{code|&amp;quot;bird&amp;quot; + &amp;quot;song&amp;quot;}} yields {{code|&amp;quot;birdsong&amp;quot;}}, while {{code|&amp;quot;song&amp;quot; + &amp;quot;bird&amp;quot;}} yields {{code|&amp;quot;songbird&amp;quot;}}). A typical counter{{citation needed|date=September 2013}} to this argument comes directly from mathematics: While + is commutative on integers (and more generally any complex number), it is not commutative for other &amp;quot;types&amp;quot; of variables. In practice, + is not even always [[operator associativity|associative]], for example with floating-point values due to rounding errors. Another example: In mathematics, multiplication is commutative for real and complex numbers but not commutative in [[matrix multiplication]].&lt;br /&gt;
&lt;br /&gt;
==Catalog==&lt;br /&gt;
A classification of some common programming languages is made according to whether their operators are overloadable by the programmer and whether the operators are limited to a predefined set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Operators&lt;br /&gt;
! Not overloadable&lt;br /&gt;
! Overloadable&lt;br /&gt;
|-&lt;br /&gt;
! New definable&amp;lt;ref&amp;gt;Completely new operators can be added.&amp;lt;/ref&amp;gt;&lt;br /&gt;
| &amp;lt;!-- &amp;quot;Not overloadable&amp;quot; and &amp;quot;New operators definable&amp;quot; --&amp;gt;&lt;br /&gt;
*[[ML (programming language)|ML]]&lt;br /&gt;
*[[Pico (programming language)|Pico]]&amp;lt;ref&amp;gt;Binary functions with a symbolic name can be called infix.&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[[Prolog]]&amp;lt;ref&amp;gt;{{cite web |url=https://www.swi-prolog.org/pldoc/man?predicate=op/3 |title=Predicate op/3}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|&amp;lt;!-- &amp;quot;Overloadable&amp;quot; and &amp;quot;New operators definable&amp;quot; --&amp;gt;&lt;br /&gt;
*[[ALGOL 68#op: Operators|ALGOL 68]]&lt;br /&gt;
*[[Clojure]]&lt;br /&gt;
*[[Eiffel (programming language)|Eiffel]]&amp;lt;ref&amp;gt;{{Cite web|title=Bertrand Meyer: Basic Eiffel language mechanisms|url=http://se.ethz.ch/~meyer/publications/online/eiffel/basic.html|access-date=2021-04-07|website=se.ethz.ch}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[[Fortran]]&amp;lt;ref&amp;gt;{{Cite web|title=Operator functions in F90|url=http://www.mathcs.emory.edu/~cheung/Courses/561/Syllabus/6-Fortran/operators.html|access-date=2021-04-07|website=www.mathcs.emory.edu}}&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;Introduced in Fortran 90.&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[[Futhark (programming language)|Futhark]]&amp;lt;ref&amp;gt;{{Cite web|title=3. Language Reference — Futhark 0.19.0 documentation|url=https://futhark.readthedocs.io/en/latest/language-reference.html|access-date=2020-10-10|website=futhark.readthedocs.io}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[[F Sharp (programming language)|F#]]&amp;lt;ref name=&amp;quot;Smith2012&amp;quot;&amp;gt;{{cite book |last=Smith |first=Chris |title=Programming F# 3.0: A Comprehensive Guide for Writing Simple Code to Solve Complex Problems |url=https://books.google.com/books?id=e0Wl6id4unQC&amp;amp;q=%22operator+overloading%22 |date=9 October 2012 |publisher=O&amp;#039;Reilly Media, Inc. |isbn=978-1-4493-2604-3}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[[Haskell (programming language)|Haskell]]&amp;lt;ref&amp;gt;[[Type class]]es instead of overloading.&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[[Io (programming language)|Io]]&amp;lt;ref&amp;gt;{{Cite web|title=io guide|url=https://iolanguage.org/guide/guide.html#Syntax-Operators|access-date=2021-04-07|website=iolanguage.org}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[[Julia (programming language)|Julia]]&amp;lt;ref&amp;gt;{{Cite web|title=Operator Overloading in Julia|url=https://www.geeksforgeeks.org/operator-overloading-in-julia/|access-date=2025-03-14&lt;br /&gt;
|website=geeksforgeeks.org}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[[Nim (programming language)|Nim]]&amp;lt;ref&amp;gt;{{cite web|title=Operators|url=https://nim-lang.github.io/Nim/tut1.html#procedures-operators}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[[R (programming language)|R]]&amp;lt;ref&amp;gt;{{Cite web|title=Operators - R in a Nutshell, 2nd Edition [Book]|url=https://www.oreilly.com/library/view/r-in-a/9781449358204/ch06s02.html|access-date=2021-04-07|website=www.oreilly.com|language=en}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[[Raku (programming language)|Raku]]&amp;lt;ref&amp;gt;{{cite web |url=https://docs.raku.org/language/optut |title=Creating operators}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[[Scala (programming language)|Scala]]&amp;lt;ref&amp;gt;{{cite web |url=https://docs.scala-lang.org/tour/operators.html |website=Tour of Scala |title=Operators}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[[Seed7]]&amp;lt;ref&amp;gt;{{Cite web|title=Seed7 Manual: Structured syntax definition|url=http://seed7.sourceforge.net/manual/syntax.htm|access-date=2020-09-29|website=seed7.sourceforge.net}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[[Smalltalk]]&amp;lt;ref name=&amp;quot;Hunt2012&amp;quot;&amp;gt;{{cite book |last=Hunt |first=John |title=Smalltalk and Object Orientation: An Introduction |url=https://books.google.com/books?id=BiDUBwAAQBAJ&amp;amp;q=overloading+operators |date=6 December 2012 |publisher=Springer Science &amp;amp; Business Media |isbn=978-1-4471-0961-7}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[[Swift (programming language)|Swift]]&amp;lt;ref&amp;gt;{{cite web |url=https://docs.swift.org/swift-book/LanguageGuide/AdvancedOperators.html |title=Swift: Advanced Operators}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Limited set&lt;br /&gt;
|&amp;lt;!-- &amp;quot;Not overloadable&amp;quot; and &amp;quot;Limited set of operators&amp;quot; --&amp;gt;&lt;br /&gt;
*[[BASIC]]&lt;br /&gt;
*[[C (programming language)|C]]&lt;br /&gt;
*[[Go (programming language)|Go]]&amp;lt;ref&amp;gt;{{cite web |title=Why does Go not support overloading of methods and operators? |url=http://golang.org/doc/go_faq.html#overloading |access-date=4 September 2011}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[[Java (programming language)|Java]]&lt;br /&gt;
*[[JavaScript]]&lt;br /&gt;
*[[Modula-2]]&lt;br /&gt;
*[[Objective-C]]&lt;br /&gt;
*[[Pascal (programming language)|Pascal]]&amp;lt;ref&amp;gt;{{Cite web|title=Introduction|url=https://www.freepascal.org/docs-html/ref/refse101.html#x213-23500015.1|access-date=2020-09-30|website=freepascal.org}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[[TypeScript]]&amp;lt;ref&amp;gt;{{cite web |title=Operator Overloads |website=[[GitHub]] |url=https://github.com/Microsoft/TypeScript/issues/5407 |access-date=28 September 2018}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[[Visual Basic]]&lt;br /&gt;
|&amp;lt;!-- &amp;quot;Overloadable&amp;quot; and &amp;quot;Limited set of operators&amp;quot; --&amp;gt;&lt;br /&gt;
*[[Ada (programming language)|Ada]]&amp;lt;ref&amp;gt;{{cite web |url=https://www.adaic.org/resources/add_content/standards/05aarm/html/AA-6-6.html |website=Annotated Ada Reference Manual |title=6.6 Overloading of Operators}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[[C Sharp (programming language)|C#]]&amp;lt;ref name=&amp;quot;DraytonAlbahari2003&amp;quot;&amp;gt;{{cite book |last1=Drayton |first1=Peter |last2=Albahari |first2=Ben |last3=Neward |first3=Ted |title=C# in a Nutshell |url=https://books.google.com/books?id=bG_Aqb6iOUYC&amp;amp;q=%22operator+overloading%22 |year=2003 |publisher=O&amp;#039;Reilly Media, Inc. |isbn=978-0-596-00526-9}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[[C++]]&amp;lt;ref&amp;gt;{{cite web |url=https://en.cppreference.com/w/cpp/language/operators |title=C++ Operator Overloading}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[[Ceylon (programming language)|Ceylon]]&amp;lt;ref&amp;gt;{{Cite web|title=Eclipse Ceylon: Operator Polymorphism|url=https://ceylon-lang.org/documentation/1.3/reference/operator/operator-polymorphism/|access-date=2021-04-07|website=ceylon-lang.org}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[[D (programming language)|D]]&amp;lt;ref&amp;gt;{{Cite web|title=Operator Overloading - D Programming Language|url=https://dlang.org/spec/operatoroverloading.html|access-date=2020-10-10|website=dlang.org}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[[Dart (programming language)|Dart]]&amp;lt;ref&amp;gt;{{Cite web|title=A tour of the Dart language|url=https://dart.dev/guides/language/language-tour|access-date=2020-09-30|website=dart.dev}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[[FreeBASIC]]&amp;lt;ref&amp;gt;{{Cite web|title=Operator Overloading|url=http://bourabai.kz/einf/freebasic/ProPgOperatorOverloading.html|access-date=2021-04-07|website=bourabai.kz}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[[Groovy (programming language)|Groovy]]&amp;lt;ref&amp;gt;{{Cite web|title=The Apache Groovy programming language - Operators|url=https://groovy-lang.org/operators.html#Operator-Overloading|access-date=2020-09-30|website=groovy-lang.org}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[[Kotlin (programming language)|Kotlin]]&amp;lt;ref&amp;gt;{{cite web |title=Operator overloading |url=https://kotlinlang.org/docs/reference/operator-overloading.html |website=Kotlin |access-date=24 June 2018}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[[Lua (programming language)|Lua]]&amp;lt;ref&amp;gt;{{cite web |url=http://lua-users.org/wiki/MetamethodsTutorial |title=Metamethods Tutorial |website=Lua-users Wiki}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[[MATLAB]]&amp;lt;ref&amp;gt;{{cite web |title=Implementing Operators for Your Class |url=http://www.mathworks.com/help/matlab/matlab_oop/implementing-operators-for-your-class.html |access-date=1 October 2013}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[[Object Pascal]] ([[Free Pascal]],&amp;lt;ref&amp;gt;{{cite web |title=Operator Overloading |website=Free Pascal Manual |url=http://www.freepascal.org/docs-html/ref/refch15.html |access-date=1 December 2014}}&amp;lt;/ref&amp;gt; [[Delphi (programming language)|Delphi]] (since 2005)&amp;lt;ref&amp;gt;{{cite web |title=Operator Overloading |website=Delphi Manual |url=http://docwiki.embarcadero.com/RADStudio/XE4/en/Operator_Overloading_%28Delphi%29 |access-date=1 December 2014}}&amp;lt;/ref&amp;gt;)&lt;br /&gt;
*[[PHP]] (using magic methods,&amp;lt;ref&amp;gt;{{cite web |title=PHP magic methods overriding class properties |url=http://webwidetutor.com/php/php-oop-Magic-Methods-tutorial-?id=30 |access-date=7 April 2015 |archive-url=https://web.archive.org/web/20160304050243/http://webwidetutor.com/php/php-oop-Magic-Methods-tutorial-?id=30 |archive-date=4 March 2016}}&amp;lt;/ref&amp;gt; ArrayAccess interface, or Operator extension)&lt;br /&gt;
*[[Perl]]&amp;lt;ref name=&amp;quot;Orwant2002&amp;quot;&amp;gt;{{cite book |last=Orwant |first=Jon |title=Computer Science &amp;amp; Perl Programming: Best of The Perl Journal |url=https://books.google.com/books?id=8TkEOyBHoOoC&amp;amp;q=%22operator+overloading%22&amp;amp;pg=PA347 |date=4 November 2002 |publisher=O&amp;#039;Reilly Media, Inc. |isbn=978-0-596-00310-4 |pages=347–}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[[Python (programming language)|Python]]&amp;lt;ref&amp;gt;{{cite web |url=https://docs.python.org/3/reference/datamodel.html |website=The Python Language Reference |title=3. Data Model}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[[Ruby (programming language)|Ruby]]&amp;lt;ref&amp;gt;{{cite web |url=https://www.ruby-lang.org/en/documentation/faq/7/ |website=Official Ruby FAQ |title=Methods}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[[Rust (programming language)|Rust]]&amp;lt;ref&amp;gt;{{cite web |url=https://doc.rust-lang.org/stable/rust-by-example/trait/ops.html |website=Rust By Example |title=Operator Overloading}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[[Visual Basic .NET]]&amp;lt;ref&amp;gt;{{cite web|title=How to: Define an Operator (Visual Basic)|date=15 September 2021 |url=https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/procedures/how-to-define-an-operator}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Timeline of operator overloading==&lt;br /&gt;
===1960s===&lt;br /&gt;
The [[ALGOL 68]] specification allowed operator overloading.&amp;lt;ref&amp;gt;{{cite web |title=Report on the Algorithmic Language ALGOL 68, Section 10.2.2. |url=https://www.softwarepreservation.org/projects/ALGOL/report/Algol68_revised_report-AB-600dpi.pdf =Barry J. Mailloux |last3=Peck |first3=John E. L. |author-link3=John E. L. Peck |last4=Koster |first4= Cornelis H. A. |author-link4=Cornelis H.A. Koster |access-date=1 April 2007 |date=August 1968  |display-authors=etal}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Extract from the ALGOL 68 language specification (page 177) where the overloaded operators ¬, =, ≠, and &amp;#039;&amp;#039;&amp;#039;abs&amp;#039;&amp;#039;&amp;#039; are defined:&lt;br /&gt;
&lt;br /&gt;
 10.2.2. Operations on Boolean Operands&lt;br /&gt;
 a) &amp;#039;&amp;#039;&amp;#039;op&amp;#039;&amp;#039;&amp;#039; ∨ = (&amp;#039;&amp;#039;&amp;#039;bool&amp;#039;&amp;#039;&amp;#039; a, b) &amp;#039;&amp;#039;&amp;#039;bool&amp;#039;&amp;#039;&amp;#039;:( a | &amp;#039;&amp;#039;&amp;#039;true&amp;#039;&amp;#039;&amp;#039; | b );&lt;br /&gt;
 b) &amp;#039;&amp;#039;&amp;#039;op&amp;#039;&amp;#039;&amp;#039; ∧ = (&amp;#039;&amp;#039;&amp;#039;bool&amp;#039;&amp;#039;&amp;#039; a, b) &amp;#039;&amp;#039;&amp;#039;bool&amp;#039;&amp;#039;&amp;#039;: ( a | b | &amp;#039;&amp;#039;&amp;#039;false&amp;#039;&amp;#039;&amp;#039; );&lt;br /&gt;
 c) &amp;#039;&amp;#039;&amp;#039;op&amp;#039;&amp;#039;&amp;#039; ¬ = (&amp;#039;&amp;#039;&amp;#039;bool&amp;#039;&amp;#039;&amp;#039; a) &amp;#039;&amp;#039;&amp;#039;bool&amp;#039;&amp;#039;&amp;#039;: ( a | &amp;#039;&amp;#039;&amp;#039;false&amp;#039;&amp;#039;&amp;#039; | &amp;#039;&amp;#039;&amp;#039;true&amp;#039;&amp;#039;&amp;#039; );&lt;br /&gt;
 d) &amp;#039;&amp;#039;&amp;#039;op&amp;#039;&amp;#039;&amp;#039; = = (&amp;#039;&amp;#039;&amp;#039;bool&amp;#039;&amp;#039;&amp;#039; a, b) &amp;#039;&amp;#039;&amp;#039;bool&amp;#039;&amp;#039;&amp;#039;:( a∧b ) ∨ ( ¬b∧¬a );&lt;br /&gt;
 e) &amp;#039;&amp;#039;&amp;#039;op&amp;#039;&amp;#039;&amp;#039; ≠ = (&amp;#039;&amp;#039;&amp;#039;bool&amp;#039;&amp;#039;&amp;#039; a, b) &amp;#039;&amp;#039;&amp;#039;bool&amp;#039;&amp;#039;&amp;#039;: ¬(a=b);&lt;br /&gt;
 f) &amp;#039;&amp;#039;&amp;#039;op&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;&amp;#039;abs&amp;#039;&amp;#039;&amp;#039; = (&amp;#039;&amp;#039;&amp;#039;bool&amp;#039;&amp;#039;&amp;#039; a)&amp;#039;&amp;#039;&amp;#039;int&amp;#039;&amp;#039;&amp;#039;: ( a | 1 | 0 );&lt;br /&gt;
&lt;br /&gt;
Note that no special declaration is needed to &amp;#039;&amp;#039;overload&amp;#039;&amp;#039; an operator, and the programmer is free to create new operators. For dyadic operators their priority compared to other operators can be set:&lt;br /&gt;
&lt;br /&gt;
  &amp;#039;&amp;#039;&amp;#039;prio&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;&amp;#039;max&amp;#039;&amp;#039;&amp;#039; = 9;&lt;br /&gt;
  &lt;br /&gt;
  &amp;#039;&amp;#039;&amp;#039;op&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;&amp;#039;max&amp;#039;&amp;#039;&amp;#039; = (&amp;#039;&amp;#039;&amp;#039;int&amp;#039;&amp;#039;&amp;#039; a, b) &amp;#039;&amp;#039;&amp;#039;int&amp;#039;&amp;#039;&amp;#039;: ( a&amp;gt;b | a | b );&lt;br /&gt;
  &amp;#039;&amp;#039;&amp;#039;op&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;&amp;#039;++&amp;#039;&amp;#039;&amp;#039; = ( &amp;#039;&amp;#039;&amp;#039;ref&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;&amp;#039;int&amp;#039;&amp;#039;&amp;#039; a ) &amp;#039;&amp;#039;&amp;#039;int&amp;#039;&amp;#039;&amp;#039;: ( a +:= 1 );&lt;br /&gt;
&lt;br /&gt;
===1980s===&lt;br /&gt;
[[Ada (programming language)|Ada]] supports overloading of operators from its inception, with the publication of the Ada 83 language standard. However, the language designers chose to preclude the definition of new operators. Only extant operators in the language may be overloaded, by defining new functions with identifiers such as &amp;quot;+&amp;quot;, &amp;quot;*&amp;quot;, &amp;quot;&amp;amp;&amp;quot; etc. Subsequent revisions of the language (in 1995 and 2005) maintain the restriction to overloading of extant operators.&lt;br /&gt;
&lt;br /&gt;
In [[C++]], operator overloading is more refined than in [[ALGOL 68]].&amp;lt;ref&amp;gt;{{cite web |title=A History of C++: 1979−1991 |url=http://www.stroustrup.com/hopl2.pdf |last=Stroustrup |first=Bjarne |author-link=Bjarne Stroustrup |page=12 |access-date=1 April 2007}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===1990s===&lt;br /&gt;
[[Java (programming language)|Java]] language designers at [[Sun Microsystems]] chose to omit overloading.&amp;lt;ref&amp;gt;{{cite web |url=http://www.cafeaulait.org/javafaq.html#xtocid1902938 |website=The comp.lang.java FAQ List |title=FAQ Question 6.9: Why isn&amp;#039;t there operator overloading?}}&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;{{cite web |url=http://java.sun.com/docs/white/langenv/Simple.doc2.html |title=java.sun.com |url-status=dead |access-date=26 March 2009 |archive-date=7 March 2009 |archive-url=https://web.archive.org/web/20090307035128/http://java.sun.com/docs/white/langenv/Simple.doc2.html }}&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;{{cite book |last=Holzner |first=Steven |title=C++: Black Book |year=2001 |publisher=Coriolis Group |location=Scottsdale, Arizona |isbn=1-57610-777-9 |page=387 |quote=One of the nicest features of C++ OOP is that you can overload operators to handle objects of your classes (you can&amp;#039;t do this in some other OOP-centric languages, like Java).}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Python (programming language)|Python]] allows operator overloading through the implementation of methods with special names.&amp;lt;ref&amp;gt;{{cite web |url=https://docs.python.org/3/reference/datamodel.html#specialnames |website=The Python Language Reference |title=3. Data Model, Special method names}}&amp;lt;/ref&amp;gt; For example, the addition (+) operator can be overloaded by implementing the method {{code|obj.__add__(self, other)}}.&lt;br /&gt;
&lt;br /&gt;
[[Ruby (programming language)|Ruby]] allows operator overloading as syntactic sugar for simple method calls.&lt;br /&gt;
&lt;br /&gt;
[[Lua (programming language)|Lua]] allows operator overloading as syntactic sugar for method calls with the added feature that if the first operand doesn&amp;#039;t define that operator, the method for the second operand will be used.&lt;br /&gt;
&lt;br /&gt;
===2000s===&lt;br /&gt;
Microsoft added operator overloading to [[C Sharp (programming language)|C#]] in 2001 and to [[Visual Basic .NET]] in 2003.&lt;br /&gt;
&lt;br /&gt;
[[Scala (programming language)|Scala]] treats all operators as methods and thus allows operator overloading by proxy.&lt;br /&gt;
&lt;br /&gt;
In [[Raku (programming language)|Raku]], the definition of all operators is delegated to lexical functions, and so, using function definitions, operators can be overloaded or new operators added. For example, the function defined in the [[Rakudo]] source for incrementing a Date object with &amp;quot;+&amp;quot; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;perl6&amp;quot;&amp;gt;&lt;br /&gt;
multi infix:&amp;lt;+&amp;gt;(Date:D $d, Int:D $x) {&lt;br /&gt;
    Date.new-from-daycount($d.daycount + $x)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since &amp;quot;multi&amp;quot; was used, the function gets added to the list of [[multidispatch]] candidates, and &amp;quot;+&amp;quot; is only overloaded for the case where the type constraints in the function signature are met.&lt;br /&gt;
While the capacity for overloading includes &amp;#039;&amp;#039;&amp;#039;+&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;*&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;&amp;gt;=&amp;#039;&amp;#039;&amp;#039;, the [[Imaginary unit|postfix and term &amp;#039;&amp;#039;&amp;#039;i&amp;#039;&amp;#039;&amp;#039;]], and so on, it also allows for overloading various brace operators: &amp;quot;&amp;#039;&amp;#039;&amp;#039;[&amp;#039;&amp;#039;&amp;#039;x, y&amp;#039;&amp;#039;&amp;#039;]&amp;#039;&amp;#039;&amp;#039;&amp;quot;, &amp;quot;x&amp;#039;&amp;#039;&amp;#039;[&amp;#039;&amp;#039;&amp;#039;y&amp;#039;&amp;#039;&amp;#039;]&amp;#039;&amp;#039;&amp;#039;&amp;quot;, &amp;quot;x&amp;#039;&amp;#039;&amp;#039;{&amp;#039;&amp;#039;y&amp;#039;&amp;#039;}&amp;#039;&amp;#039;&amp;#039;&amp;quot;, and &amp;quot;x&amp;#039;&amp;#039;&amp;#039;(&amp;#039;&amp;#039;&amp;#039;y&amp;#039;&amp;#039;&amp;#039;)&amp;#039;&amp;#039;&amp;#039;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Kotlin (programming language)|Kotlin]] has supported operator overloading since its creation.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
*[[Function overloading]]&lt;br /&gt;
*[[Polymorphism (computer science)]]&lt;br /&gt;
*[[Subroutine]]&lt;br /&gt;
*[[Operator (programming)]]&lt;br /&gt;
*[[Operators in C and C++]]&lt;br /&gt;
*[[Mutator method]]&lt;br /&gt;
*[[Indexer (programming)]]&lt;br /&gt;
*[[Property (programming)]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{Reflist|30em}}&lt;br /&gt;
&lt;br /&gt;
{{Authority control}}&lt;br /&gt;
&lt;br /&gt;
{{DEFAULTSORT:Operator Overloading}}&lt;br /&gt;
[[Category:Articles with example ALGOL 68 code]]&lt;br /&gt;
[[Category:Operators (programming)]]&lt;/div&gt;</summary>
		<author><name>imported&gt;Adius</name></author>
	</entry>
</feed>