C++函数重载
1 //函数重载
2 #include <iostream>
3 using namespace std;
4 //可以让函数名相同 提高复用性
5
6 //函数重载满足条件
7 //1.同一个作用域下
8 //2.函数名相同
9 //3.函数参数类型不同,个数,顺序不同
10
11 //注意: 函数的返回值 不可以作为函数重载的条件
12
13 //int func(double a, int b)
14 //{
15 // cout << "func (double a ,int b)的调用!" << endl;
16 //}
17 void func()
18 {
19 cout << "func的调用" << endl;
20 }
21
22 void func(int a)
23 {
24 cout << "func(int a)的调用" << endl;
25 }
26 void func(double a)
27 {
28 cout << "func(double a)的调用" << endl;
29 }
30
31 void func(int a ,double b)
32 {
33 cout << "func(int a ,double b)的调用" << endl;
34 }
35 void func(double a, int b)
36 {
37 cout << "func(double a, int b)的调用" << endl;
38 }
39 int main()
40 {
41 func();
42 func(10);
43 func(3.14);
44 func(10, 3.14);
45 func(3.14, 10);
46 }

本文来自博客园,作者:Bytezero!,转载请注明原文链接:https://www.cnblogs.com/Bytezero/p/15101951.html
浙公网安备 33010602011771号