Overloads of C + +
In some programming languages, function overloading or method overloading are the ability to create multiple methods of the Same name with different implementations. Calls to an overloaded function would run a specific implementation of that function appropriate to the context of the call , allowing one function call to perform different tasks depending on context.
For example, Dotask () and Dotask (object O) is overloaded methods. To call the latter, an object must being passed as a parameter, whereas the former does not require a parameter, and is Calle D with an empty parameter field. A common error would is to assign a default value to the object in the second method, which would result in an ambiguous C All error, as the compiler wouldn ' t know which of the the and methods to use.
Another appropriate example would be a Print (object O) method. In this case one might like the method to being different when printing, for example, text or pictures. The different methods may be overloaded as Print (Text_object T); Print (Image_object P). If we write the overloaded print methods for all objects our program would "print", we never has to worry about the type O f the object, and the correct function call again, which is always:print (something).
The following program implements overloading of functions.
#include <stdlib.h> #include <iostream>using namespace std;void fun (int i=30, int j=20, int k=10), int main (voi D) {fun (); fun (+); Fun (+, +); System ("pause"); return 0;} void Fun (int i, int j, int k) {cout << i << "," << J << "," << K<<endl;}
program, the same name function, the number of function parameters are different, run the result:
function overloading of C + +