当前位置:网站首页>Function overloading

Function overloading

2022-07-05 04:34:00 On the bald Road

The so-called heavy load and yes “ Use one thing more ”.

Heavy load condition : Number of parameters , Parameter type , There is at least one difference in the order of the parameters , Whether the return value of the function is the same or not is irrelevant . Is to consider whether there is ambiguity when calling functions .

Example overloads with different number of parameters :

#include<iostream>
using namespace std;
int max(int, int);
int max(int, int, int);
int main() {
	cout << max(5, 6) << endl;;
	cout << max(5, 9, 7);
	return 0;

}
int max(int a, int b) {
	if (a < b) {
		a = b;
	}
	return a;
}
int max(int a, int b, int c) {
	if (a < b) {
		a = b;
	}
	if (a < c) {
		a = c;
	}
	return a;
}

原网站

版权声明
本文为[On the bald Road]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140636192979.html