Jump to content

Operator overloading

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Taw (talk | contribs) at 22:34, 2 December 2001 (initial version). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

Programming technique, in which some or all of operators like "+", "=" or "==" are treated as functions and can be defined

or redefined for new types. Sometimes defining new operators is allowed.

This is usually only a syntactic sugar, and it can be easily emulated by function calls:


With operator overloadinga + b * c
Without operator overloadingour_new_type_add (a, our_new_type_multiply (b,c))


Only in case when operators can be called implicitely they are of some use other than esthetics. This is the case with Ruby operator to_s, which returns object representation of string and with operators in PostgreSQL, where mathematical transformations can be defined on

operators and PostgreSQL may use many optimalizations to expressions that use them.


Please add more languages to this list


Languages that support operator overloading and declaring new operators: PostgreSQL version of SQL Ruby


Languages that support operator overloading: Ada, C++, C#


Languages that don't support operator overloading: C, Java, Pascal