#include #include #include "IntCell.h" using namespace std; // Return the maximum item in array a. // Assume a.size( ) > 0. // Comparable objects must provide operator< template const Comparable & findMax( const vector & a ) { int maxIndex = 0; for( int i = 1; i < a.size( ); i++ ) if( a[ maxIndex ] < a[ i ] ) maxIndex = i; return a[ maxIndex ]; } #include "IntCell.h" #include using namespace std; int main( ) { vector v1; vector v2; vector v3; vector v4; vector v5; v1.push_back( 37 ); v1.push_back( 15 ); v1.push_back( 22 ); v2.push_back( 3.7 ); v2.push_back( 1.5 ); v2.push_back( 2.2 ); v3.push_back( "37" ); v3.push_back( "15" ); v3.push_back( "4" ); v4.push_back( IntCell( 37 ) ); v4.push_back( IntCell( 15 ) ); v5 = v1; v5.push_back( 39 ); cout << findMax( v1 ) << endl; // OK: Comparable = int cout << findMax( v2 ) << endl; // OK: Comparable = double cout << findMax( v3 ) << endl; // OK: Comparable = string // cout << findMax( v4 ) << endl; // Illegal: no operator< cout << findMax( v5 ) << endl; // OK: uses findMax, line 15 return 0; }