Operator overloading (less commonly known as ad-hoc polymorphism) is a programming technique in which some or all of operators like +, = or == can be treated as functions and can be defined or redefined for new types. Operators need not be symbols. Sometimes defining new operators is allowed. This is usually only a syntactic sugar, and it can be easily emulated by function calls:
with operator overloading
- a + b × c
- our_new_type_add (a, our_new_type_multiply (b,c))
Criticism
Operator overloading has been criticised because it allows programmers to give operators completely different functionality depending on the types of their operands. C++'s usage of the "<<" operator is a particularly bad example: The expression
a << 1will return two times the value of a if a is an integer variable, but if a is an output stream instead this will write "1" into it.
Catalog
Languages that support operator overloading and declaring new operators: PostgreSQL version of SQL, Ruby, Haskell
Languages that support operator overloading: Ada, C++, C#, D, Python, Ruby
Languages that don't support operator overloading: C, Pascal, Delphi, Java, Visual Basic, Perl