正在加载图片...
例61函数模板的程序 i include<iostream h> # include≤ string. h> 程序运行结果如下: template<classat> the max of il, i2 is: 56 AT max(aT X,AT y) the max of fl f2 is: 24.5 i return(x>y)? x: y; 3 the max of dl d2 is: 4656.346 void maino the max of cl c2 is ' n i int il=10, 12=56; float f=12.5,f2=24.5 double b1=50.344,d2=4656346; char cl=kc2=n cout<<the max of il, i2 is: "<<max (i1, 12 <<endl; cout” the max of fl,f2is:“max(f1,f2)<<end; cout” the max of dld2is:“<<max(d1,d2)<endl; cout” the max of clc2is:“<<max(c1,c2)<endl;例6.1 函数模板的程序 # include<iostream.h> # include<string.h> template<class AT> AT max(AT x , AT y ) { return (x>y)? X : y; } void main() { int il=10, i2=56; float fl=12.5, f2=24.5; double b1=50.344,d2=4656.346; char c1=’k’,c2=’n’; cout<<”the max of il,i2 is: “<<max(i1,i2)<<endl; cout<<”the max of fl,f2 is: “<<max(f1,f2)<<endl; cout<<”the max of dl,d2 is: “<<max(d1,d2)<<endl; cout<<”the max of cl,c2 is: “<<max(c1,c2)<<endl; } 程序运行结果如下: the max of il,i2 is :56 the max of fl,f2 is :24.5 the max of dl,d2 is :4656.346 the max of cl,c2 is :n 4
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有