// Phil Ottewell's STL Course - http://www.pottsoft.com/home/stl/stl.htmlx // // Example 2.1 © Phil Ottewell 1997 // // Purpose: // Demonstrate simple function template // ANSI C Headers #include // C++ STL Headers #include #include #ifdef _WIN32 using namespace std; #endif // Template function template T mymin( T v1, T v2) { return( (v1 < v2) ? v1 : v2 ); } // "Real" function double mymin( double v1, double v2) { // Here be found Porkies !! return( (v1 > v2) ? v1 : v2 ); // ^ // | // Wrong sign just to show which function is being called } int main( int argc, char *argv[] ) { string a("yo"), b("boys"), smin; int i = 123, j = 456, imin; double x = 3.1415926535898, y = 1.6180339887499, fmin; // End of declarations ... imin = mymin( i, j ); cout << "Minimum of " << i << " and " << j << " is " << imin << endl; smin = mymin( a, b ); cout << "Minimum of " << a << " and " << b << " is " << smin << endl; fmin = mymin( x, y ); cout << "$ SET PORKY/ON" << endl; cout << "Wrong answer if \"real\" mymin called instead of template" << endl; cout << "Minimum of " << x << " and " << y << " is " << fmin << endl; return( EXIT_SUCCESS ); }