C++ examples for template:template function
Using int, char and float to test maximum template function
#include <iostream> template <typename T> T maximum(T num1, T num2) {//from w w w. ja v a 2 s . c o m return (num1 > num2) ? num1 : num2; } int main(int argc, const char *argv[]) { // int std::cout << "maximum(58, 78): " << maximum(58, 78) << std::endl; // char std::cout << "maximum('A', '#'): " << maximum('A', '#') << std::endl; // double std::cout << "maximum(1.359, 1.3598): " << maximum(1.359, 1.3598) << std::endl; return 0; }