Home > Programming > Functions using the "C" programming language > example35.cpp |
Previous |
/*
In this example we demonstrate how to use function templates.
*/
/*
Note: C++ compiler is needed.
*/
#include <stdio.h>
#include <conio.h>
template <class T>
T max(T x, T y)
{
return (x > y) ? x : y;
};
void main()
{
int i = 1;
int j = 2;
char a = 'a';
char b = 'b';
printf("Integer max is %d.\n",max(i,j));
printf("Character max is %c.\n",max(a,b));
getch();
}
© 2004 Jim Valavanis
Previous |