函数重载。
如果一个类有多个名字相同但参数不同的函数,那么它们就被称为重载。
函数重载允许你对不同的函数使用相同的名称,在同一个类中完成相同或不同的任务。如果你只需要执行一个操作,但有不同的数量或参数类型,你可以简单地重载该函数。
比如说
#include<iostream
使用命名空间std;
int sum(int x,int y)
{
cout<< x+y;
}
double sum(double x,double y)
{
cout << x+y;
}
int main()
{
sum(10,20);
sum(10.5,20.5);
返回0。
}
输出。
The postFunction Overloadingappeared first oni2tutorials.