首页 > 其他 > 详细

函数模板特化

时间:2016-12-03 23:31:23      阅读:283      评论:0      收藏:0      [点我收藏+]
#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;
}

 

函数模板特化

原文:http://www.cnblogs.com/zzyoucan/p/6129654.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!