代码修改如下:
#include <iostream>
#include <cstdlib>
template<class Type>
Type * min(Type * r_array, int size)
{
Type * min_val = NULL;
if(r_array && size>0)
{
min_val = r_array;
for(int i=1;i<size;++i)
{
if(*min_val>r_array[i])
{
min_val = r_array+i;
}
}
}
return min_val;
}
int main()
{
int ia[]={1,5,7,9,0};
double da[]={1.2,2.5,6.1,9.8,10.6};
int size_ia = sizeof(ia)/sizeof(int);
int size_da = sizeof(da)/sizeof(double);
int * i = min(ia, size_ia);
using std::cout;
using std::endl;
if(*i != 0)
{
cout<<\"it is wrong\"<<endl;
}
else
{
cout<<\"it is right\"<<endl;
}
double * d = min(da, size_da);
if(*d!=1.2)
{
cout<<\"it is wrong\"<<endl;
}
else
{
cout<<\"it is right\"<<endl;
}
system(\"pause\");
return 0;
}
自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!