Operator overloading
In computer programming, operator overloading (less commonly known as operator ad-hoc polymorphism) is a specific case of polymorphism in which some or all of operators like +, = or == have different implementations depending on the types of their arguments. Operators need not always be symbols. Sometimes the overloadings are defined by the language, sometimes the programmer can implement support for new types.
Related Topics:
Computer programming - Ad-hoc - Polymorphism - Polymorphism - Operator
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Operator overloading (operator syntax and overloading generally) is usually only syntactic sugar. It can easily be emulated using function calls; for an example, consider for integers a, b, c:
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
:a + b × c
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
In a language that supports operator overloading this is effectively a more concise way of writing:
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
:operator_add_integers (a, operator_multiply_integers (b,c))
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
(Assuming the × operator has higher precedence than +.)
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
However, in C++ templates or even C macros, operator overloading is needed in writing down generic, primitive operations such as summing elements when implementing a vector template. The only way to write primitive addition is a + b and this works for all types of elements only because of its overloading. (Actually, in C++ one could define an overloaded function add to use instead, but not in C.)
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
~ Table of Content ~
| ► | Introduction |
| ► | Criticisms |
| ► | Catalog |
~ What's Hot ~
~ Community ~
| ► | History Forum Come and discuss about History, Civilizations, Historical Events and Figures |
| ► | History Web-Ring A community of sites, blogs and forums dedicated to History. Do not hesitate to submit your site. |
and are licensed under the GNU Free Documentation License.
Lexicon - Privacy Policy - Spiritus-Temporis.com ©2005.