Simple C++ template char* and int, different strcmp output ?

#include <stdio.h>
#include <string.h>
//max returns the maximum of the two elements
template <class T> T max(T a, T b)
{
    return a > b ? a : b ;
}

// Specialization of max for char*
template <> char* max(char* a, char* b)
{
    return strcmp(a, b) > 0 ? a : b ;
}

int main()
{
    printf( "%d ", max(10, 15) );
    printf( "%s\n", max("Aladdin", "Jasmine") );
    return 0 ;
}

Output :
Windows: 15 Jasmine
Linux : 15 Aladdin

Reference:
http://www.iis.sinica.edu.tw/~kathy/vcstl/templates.htm

Advertisements