template typename int size min3 const r_array size min_val r_array for

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
template <typename T, int size>
T min3( const T (&r_array)[size] )
{
T 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;
}
const int size = 5;
int ia[size];
int _tmain(int argc, _TCHAR* argv[])
{
ia[0] = 4;
ia[1] = 5;
ia[2] = 6;
ia[3] = 2;
ia[4] = 5;
int min_element = 0;
min_element = min3((ia));
cout << min_element << endl;
return 0;
}