forked from bbw7561135/Numerical-Algorithms-2020
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunc_reload.cpp
More file actions
99 lines (60 loc) · 1.33 KB
/
func_reload.cpp
File metadata and controls
99 lines (60 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
using namespace std;
//函数重载需要函数都在同一个作用域下
//void func()
//{
// cout << "func 的调用!" << endl;
//}
//void func(int a)
//{
// cout << "func (int a) 的调用!" << endl;
//}
//void func(double a)
//{
// cout << "func (double a)的调用!" << endl;
//}
//void func(int a ,double b)
//{
// cout << "func (int a ,double b) 的调用!" << endl;
//}
//void func(double a ,int b)
//{
// cout << "func (double a ,int b)的调用!" << endl;
//}
//函数返回值不可以作为函数重载条件
//int func(double a, int b)
//{
// cout << "func (double a ,int b)的调用!" << endl;
//}
//函数重载注意事项
//1、引用作为重载条件
void func(int &a)
{
cout << "func (int &a) 调用 " << endl;
}
void func(const int &a)
{
cout << "func (const int &a) 调用 " << endl;
}
//2、函数重载碰到函数默认参数
void func2(int a, int b = 10)
{
cout << "func2(int a, int b = 10) 调用" << endl;
}
void func2(int a)
{
cout << "func2(int a) 调用" << endl;
}
int main()
{
// func();
// func(10);
// func(3.14);
// func(10,3.14);
// func(3.14,10);
int a = 10;
func(a); //调用无const
func(10);//调用有const
// func2(10); //碰到默认参数产生歧义,需要避免
return 0;
}