# Function overloading

Function overloading

Function is the name of an operation, when the name on behalf of multiple operations in natural language and in turn each of these operations are not the same, we need to be overloaded functions that share a plurality of operation function name.

Two or more functions, with the same function name, but a different number or type parameters and arguments, which the compiler will automatically calls the number according to the best match and the type of the parameter and the parameter, which is overloaded function.

Example:
When you are three-digit multiplication of multiplication and digit number of parameters due to the different shape can not use the same function, which requires heavy load function.
int multiply(int x,int y);
int multiply(int x,int y,int z);

#include<iostream>
 using namespace std;
 int multiply(int x,int y){
     return x*y;
 }
int multiply(int x,int y,int z){
    return x*y*z;
}
int main()
{
int x,y;
cout<<"enter two number:";
cin>>x>>y;
cout<<"结果是:"<<multiply(x,y)<<endl;
int a,b,c;
cout<<"enter theer number:";
cin>>a>>b>>c;
cout<<"结果是:"<<multiply(a,b,c)<<endl;

return 0;
}

【作者】 ( https://www.cnblogs.com/wxllovezn/ )

Guess you like

Origin www.cnblogs.com/wxllovezn/p/11504753.html