__________________________________________________________________________________________________________________________________________ 下面的是正确的,后面的有点小问题。 #include
#include
#include
using namespace std;
template
AnyType maxn(AnyType arr[],int size)//模板类
{
AnyType max=arr[0];
for(int i=0;i<size;i++)
{
if(arr[i]>max)
max=arr[i];
}
return max;
};
template <>string maxn
{
int max=0;//用于记录最大的字符串长度
int temp=0;//用于记录字符串长度
int place=0;//用于记录所在位置
for(int i=0;i<size;i++)
{
temp=arr[i].length();
if(temp>max)
{
max=temp;
place=i;//记录字符串所在位置
}
}
//return arr[max];
return arr[place];
};
void main86()
{
int a[6]={10,3,50,45,33,60};
double b[4]={4.5,6.7,2.5,3.1};
string c[5]={“you”,”heheshui”,”oo”,”tianxia”,”end”};
cout<<”The amax is “<<maxn(a,6)<<endl;
cout<<”The bmax is “<<maxn(b,4)<<endl;
cout<<”The cmax is “<<maxn(c,5)<<endl;
system(“pause”);
}
—————————————————————————————————————————————————— //写的错误或者不好的地方请多多指导,可以在下面留言或者给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。 转载请注明出处:https://www.royalchen.com/ author:royalchen Email:royalchen@royalchen.com ———————————————————————————————————————————————————
- 本文作者: royalchen
- 本文链接: http://www.royalchen.com/2016/02/24/cprimerplus第六版课后编程题答案86/
- 版权声明: 本博客所有文章除特别声明外,均采用 MIT 许可协议。转载请注明出处!