#include <iostream>
#include <string>
using namespace std;
#include <windows.h>
/*
函数重载的条件
1 同一个作用域
2 函数名称相同
3 函数参数类型不同,或者个数不同,或者顺序不同
ps 函数的返回值不可以作为函数重载的条件
*/
void test() {
cout << "test" << endl;
}
void test(int a) {
cout << a << endl;
}
void test(double a) {
cout << a << endl;
}
void test2(int &a) {
cout << a << endl;
}
void test2(const int &a) {
cout << a << endl;
}
int main() {
test();//输出 test
test(123);//输出 123
test(3.14);//输出3.14
int x = 10;
test2(x);//输出 10
test2(20);//输出20
system("pause");
return 0;
}
利用函数重载编写函数max_c++笔记(函数重载)
最新推荐文章于 2023-04-24 13:01:49 发布