#pragma warning(disable:4305)
#include<iostream>
using namespace std;
template<typename Type,int size>
Type min(Type (&r_array)[size])
{
Type min_val=r_array[0];
for(int i=1;i<size;i++)
if(r_array[i]<min_val)
min_val=r_array[i];
return min_val;
}
int main()
{
float f[10]={0.3,0.2,0.1,0.4,1.0,0.5,0.6,0.7,0.8,0.9};
int n[5]={1,5,2,3,4};
cout<<min(n);
return 0;
}
错误:
error C2265: '<Unknown>' : reference to a zero-sized array is illegal
error C2784: 'Type __cdecl min(Type (&)[1])' : could not deduce template argument for ' (&)[1]' from 'int [5]'