C++模板函数初次使用

#include <iostream>

using namespace std;

template <typename T>
T max(T m1, T m2)
{
    return (m1>m2)?m1:m2;
}

template <typename T>
T min(T m1, T m2)
{
    return (m1<m2)?m1:m2;
}

void main()
{
    cout<<max("ABC","ABD")<<","<<min("ABC","ABD")<<","
        <<min('W','T')<<","<<min(2.0,5.)<<endl;
}
![程序运行结果](http://img.blog.csdn.net/20150717221847933)

你可能感兴趣的:(template)