C++ template function that returns the greater of two types

Description

C++ template function that returns the greater of two types

#include <cstdio>
#include <cstdlib>
#include <iostream>

using namespace std;

template <class T> T maximum(T t1, T t2)
{
    return (t1 > t2) ? t1 : t2;
}

int main(int argc, char* pArgs[])
{
    cout << "maximum(-1, 2) = "<<maximum(-1, 2) << endl;

    cout << "maximum(1, 2.5) = "<<maximum<double>(1, 2.5) << endl;

    return 0;/* w w  w .j a v  a2 s .c  om*/
}



PreviousNext

Related