header-langage
简体中文
English
Tiếng Việt
Scan to Download the APP
Partnered With:

Simple Introduction to Solidity|Lecture 16: Function Overloading

Read this article in 4 Minutes
This article introduces the basic usage of function overloading in solidity.
Original title: "Introduction to Solidity Minimalist: 16. Function Overloading" "
Original author: 0xAA


I am re-learning solidity recently, to consolidate the details, and also write an "Introduction to Solidity Minimalist", For novices (programmers can find other tutorials), 1-3 lectures are updated every week.


All codes and tutorials are open source on github: github.com/AmazingAng/WTFSolidity



Solidity allows functions to be overloaded (overloading), that is, functions with the same name but different input parameter types can exist at the same time, and they are regarded as different functions . Note that solidity does not allow modifier overloading.


Function overloading


For example, we can define both as saySomething( ) functions, one without any parameter, outputs "Nothing"; the other receives a string parameter, and outputs this string.



Argument Matching


When calling an overloaded function, the input actual parameter and the variable of the function parameter will be type to match.


If there are multiple matching overloaded functions, the solidity documentation says that an error will be reported. The example it gives is two functions called f(), one parameter is uint8 and the other is uint256. The document says that if you enter 50, it can be converted to uint8 or uint256, so an error will be reported. But I didn't meet:



Summary


In this lecture, we introduced the basic usage of function overloading in solidity: the same name But functions with different input parameter types can exist at the same time, and they are regarded as different functions.


Original link


Welcome to join the official BlockBeats community:

Telegram Subscription Group: https://t.me/theblockbeats

Telegram Discussion Group: https://t.me/BlockBeats_App

Official Twitter Account: https://twitter.com/BlockBeatsAsia

举报 Correction/Report
Choose Library
Add Library
Cancel
Finish
Add Library
Visible to myself only
Public
Save
Correction/Report
Submit