Function overloading: Difference between revisions

Content deleted Content added
Add reference & over loadings are distinguished by type signature, which can include return type (as in Ada) or just parameters (as in C++). More impartial phrasing. Still much to do...
m Title linked in text
Line 34:
* [[Nim (programming language)|Nim]]<ref>{{cite web|title=Nim Manual|url=https://nim-lang.org/docs/manual.html#overloading-resolution|website=nim-lang.org|language=en}}</ref>
* [[Crystal (programming language)|Crystal]]<ref>{{cite web|title=Crystal Docs|url=https://crystal-lang.org/reference/1.8/syntax_and_semantics/overloading.html|website=crystal-lang.org|language=en}}</ref>
* [[Delphi_Delphi (software)|Delphi]]<ref>{{cite web|title=Embarcadero Delphi|url=https://docwiki.embarcadero.com/RADStudio/Athens/en/Overloading|website=embarcadero.com|language=en}}</ref>
 
==Rules in function overloading==
* The same function name is used for more than one function definition in a particular module, class or namespace
* The functions must have different [[Typetype signature|type signatures]]s, i.e. differ in the number or the types of their formal parameters (as in C++) or additionally in their return type (as in Ada).<ref>{{cite book
| last1 = Watt
| first1 = David A.
Line 47:
| publisher = John Wiley & Sons, Inc.
| isbn = 978-0-470-85320-7
| pages = 204-207204–207
}}
</ref>
Line 57:
The mistake comed from confusion in each form of static polymorphism as following:
* ''[[Parametric polymorphism]]'' differs from overloading by that the function definition exists only ones and this function invoked with parameters of different types which are substituted formal parameter types.
* ''[[Ad hoc polymorphism]]'' is very similar to overloading but it's depends of a language. This classification was introduced by [[Christopher Strachey]] in 1967, but difference is that he applied for compiler specific features which was exists in some programming languages. It was possibly to define in a module only name of a function and have in another module a multiple functions with same name(exact [[Function overloading|function overloading]]) so one module doesn't have access to another module until compiled. Thus was created effect that in first module was used same function for different parameters but it was just a cosmetic effect therefore [[Christopher Strachey]] gave it such special name as "ad hoc". But not any language has same feature, e.g. in [[Java (programming language)|Java]], there is no possibility define such function, similar example in Java can be achieved by using common interface for both modules but interface should have exact function signature thus ''[[Ad hoc polymorphism]]'' can't be applied.
 
Function overloading differs from forms of [[Polymorphism (computer science)|polymorphism]] where the choice is made at runtime, e.g. through [[virtual function]]s, instead of statically.