// Another function template example // #include #include #include using namespace std; // This is a function template for a function that returns the value // of the element of greatest absolute value of a 1-D array template my_type inf_norm( int size, my_type array[] ) { my_type greatest = abs( array[0] ); for ( int i = 1; i < size; i++ ) { if ( abs( array[i] ) > greatest ) greatest = abs( array[i] ); } return( greatest ); } int main() { int iy, ix[5] = { 9, 2, -16, -4, 0 }; float fy, fx[4] = { -7.8, 5.2, -9.886, 13.7 }; double dy, dx[6] = { 7.8, -54.765, 9.65, 87.543, -6.54 }; long double ly, lx[3] = { 7.99875, -6.5432, 8.97643 }; iy = inf_norm( 5, ix ); cout << iy << " " << sizeof( iy ) << endl; fy = inf_norm( 4, fx ); cout << fy << " " << sizeof( fy ) << endl; dy = inf_norm( 6, dx ); cout << dy << " " << sizeof( dy ) << endl; ly = inf_norm( 3, lx ); cout << ly << " " << sizeof( ly ) << endl; cout << "\n\n"; system( "PAUSE" ); return( EXIT_SUCCESS ); }