函数模板特化

#include <iostream>
template <typename T>
T max(T x, T y)
{
    return x > y ? x : y;
}

//函数模板特化
template <>
const char* max(const char* x, const char* y){
    return strcmp(x, y) > 0 ? x : y;
}

int main(){
    std::cout << max(1, 2);
    std::cout << max("hello", "world");
    return 0;
}

 

posted @ 2016-12-03 21:11  zzyoucan  阅读(1212)  评论(0编辑  收藏  举报