码迷,mamicode.com
首页 > 编程语言 > 详细

C++函数模板举例

时间:2017-09-11 22:53:48      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:函数模板

#include <iostream>

using namespace std;

template<typename T>
T max(const T &a,const T &b,const T &c)
{
    T temp=(a>b)?a:b;
    return (temp>c)?temp:c;
}
int main(int argc, char *argv[])
{
    int a=10;
    int b=22;
    int c=15;

    cout<<max(‘a‘,‘b‘,‘c‘)<<endl;
    cout<<max(a,b,c)<<endl;
    cout<<max(55.55,11.11,44.44)<<endl;

    return 0;
}

技术分享

本文出自 “10628473” 博客,请务必保留此出处http://10638473.blog.51cto.com/10628473/1964433

C++函数模板举例

标签:函数模板

原文地址:http://10638473.blog.51cto.com/10628473/1964433

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!