现在的位置: 首页 > 综合 > 正文

一个简单的函数模版

2014年01月30日 ⁄ 综合 ⁄ 共 345字 ⁄ 字号 评论关闭
#include <iostream>
#include <string>
#include <cstring>


using namespace std;


template <typename T>
inline T const& max(T const& a, T const& b)
{
    return a > b ? a : b;
}
char const* max(char const* str1, char const* str2)
{
    return strcmp(str1, str2) > 0 ? str1 : str2;
}


int main(int argc, char *argv[])
{
    cout << ::max("hello", "world") << endl;
    cout << ::max(string("hello"), string("world")) << endl;
    return 0;
}

抱歉!评论已关闭.