首页 > 代码库 > 模板初try

模板初try

#include<iostream>
using namespace std;
//如果不会,不妨由会开始
//1~FIRST:
//int mmax(int a,int b)
//{
//    return a>b?a:b;
//}
//2~SECOND:
//    T mmax(T a,T b)
//{
//    return a>b?a:b;
//}
//3~THIRD:
    template<class T>
T mmax(T a,T b)
{
    return a>b?a:b;
}
int main()
{
    cout<<mmax(‘c‘,‘d‘)<<endl;
    cout<<mmax(3,5)<<endl;
    cout<<mmax(3.3,9.6)<<endl;
    cout<<mmax<int>(3.3,9.6)<<endl;
    cout<<mmax((int)3.3,(int)9.6)<<endl;
}

模板初try