C++函数重载

C++函数重载:

函数重载:是函数的一种特殊情况,C++允许在同一作用域中声明几个功能类似的同名函数,这些同名函数的形 参列表(参数个数 或 类型 或 顺序)必须不同,常用来处理实现功能类似数据类型不同的问题

#include <iostream>
#include <stdlib.h>
using namespace std;
//全缺省参数
void TestFunc1(int a = 10,int b=20,int c=30) 
//10,20,30为函数的缺省参数,当函数没有传参数时 10位默认函数参数
{
 cout << a << endl;
 cout << b << endl;
 cout << c << endl;
}
//半缺省参数
void TestFunc2(int a = 10, int b = 20, int c = 30) 
{
 cout << a << endl;
 cout << b << endl;
 cout << c << endl;
}
int Add(int a, int b) {
 return a + b;
}
double Add(double a, double b) {
 return a + b;
}
int Add(int a, double b) {
 return a+b;
}
int Add(double a, int b) {
 return a+b;
}
int main() {
 TestFunc1(10);
 TestFunc1(20);
 TestFunc1(30);
 TestFunc2(10);
 system("pause");
 return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值