overload max-重载max函数
//overload max函数 #include<iostream> double max(double a,double b); double max(double a,double b,double c); int main() { using namespace std; double maxoftwo,maxofthree; double a = 3,b = 7; double x = 1.1,y = 2.2,z = 3.3; maxoftwo = max(a,b); maxofthree = max(x,y,z); cout<<"Max of the two numbers is:"<<maxoftwo<<endl; cout<<"Max of the three numbers is:"<<maxofthree<<endl; return 0; } double max(double a,double b) { if(a > b) return a; return b; } double max(double a,double b,double c) { double tem; tem = a >b?a:b; return c>tem?c:tem; }
结果:
Max of the two numbers is:7 Max of the three numbers is:3.3
原文地址:http://9320314.blog.51cto.com/9310314/1546912