What is the overload of the function?
Function is a function of many programming languages where you can create multiple methods with the same name, but with different input parameters or return types. This is a common feature in object -oriented programming; In particular, designers can have several different overloaded variants. Overloading functions is basically useful when two functions do very similar things and can take more types of inputs. Constructors can be easily overloaded because they do not have a specified explicit return type, so that the constructor's input parameters would simply be valid overload.
The first way to overload is a change in input parameters. For example, a feature called “Add”, which occupies two integers as an input. The purpose of this function is quite obvious; The purpose is to find the sum of two integers.
If someone wanted to find the sum of two floats or decimal numbers, this function could not be used. Thus, a second overloaded function would be necessaryVana as a function called "Add", which takes two floats as input. The functions are essentially the same, but the overload of the function is necessary because their inputs are significantly different.
The second way to overload the function is to change the input parameters and the return type. Using the previous example, it is possible to consider whether both overloaded functions "add" had a type of return of empty; That means they didn't return anything. This would still be valid overload of the function, but the types of return on both methods can also be changed. In the next valid example of overload, the "add" function, which takes two full numbers, could return the full sum of the "add" number, which takes two decimal numbers, could return this sum of decimal numbers.
Simply changing the type of return of the function is not considered to be a valid overload of the function. Changing only the return of the function leads to ambiguity because it is not clear in terms of signature of the method, toTerý is required to return the return. Parameters can also be defined ambiguously, so it is very important that the overloaded functions are correctly called. For example, if a person has an overloaded function that has an integer as an input parameter, and the other that has a decimal number as a parameter, it would be very easy for someone to call the decimal number instead of the whole function or vice versa because it has the same name. If possible, it is necessary to prevent unclear parameters such as these, and if they cannot be, it is necessary to pay close attention to ensuring that the correct overloaded function is called in the right times.
Function is useful for creating related functions with different types of inputs and giving the code of great flexibility. One last reflection of overloaded functions is that adequate comments are necessary. Although it could be clear, according to the various input parameters, which version of the overloaded function is in order for a particular situation, may not always be clear whatThis feature makes other overloaded partners.