『代码』··By/蜜汁炒酸奶

函数重载-C++

/*
功能:函数重载
日期:2013-09-23
*/
#include <iostream>
using namespace std;

int fun(int a=1,int b=2)
{
	int sum;

	sum = a * a + b * b;

	return sum;
}
float fun(float a,float b)
{
	float sum;

	sum = a * a + b * b;

	return sum;
}
double fun(double a,double b)
{
	double sum;

	sum = a * a + b * b;

	return sum;
}
int main(void)
{

	cout<<"fun():"<<fun()<<endl;
	cout<<"fun(2.5f,3.3f):"<<fun(2.5f,3.3f)<<endl;
	cout<<"fun(1.5,1.2):"<<fun(1.5,1.2)<<endl;

	system("pause");
	return 0;
}
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

预览
Loading comments...
6 条评论
  • W

    编程都是相通啊

    • W

      回复 @Joe: 恩恩,是滴

  • W

    编程基础

  • W

    哇,C++,看不懂!

example
预览