Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Function overloading
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Basic definition == For example, {{mono|doTask()}} and {{nowrap|{{mono|doTask(object o)}}}} are overloaded functions. To call the latter, an [[object (computer science)|object]] must be passed as a [[parameter (computer science)|parameter]], whereas the former does not require a parameter, and is called with an empty parameter field. A common error would be to assign a default value to the object in the second function, which would result in an ''ambiguous call'' error, as the [[compiler]] wouldn't know which of the two methods to use. Another example is a {{nowrap|{{mono|Print(object o)}}}} function that executes different actions based on whether it's printing text or photos. The two different functions may be overloaded as {{nowrap|{{mono|Print(text_object T); Print(image_object P)}}.}} If we write the overloaded print functions for all objects our program will "print", we never have to worry about the type of the object, and the correct function call again, the call is always: {{mono|Print(something)}}.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)