标题:c++函数模板重载问题(DEVC++编译器)
取消只看楼主
x1296919830
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2017-6-8
 问题点数:0 回复次数:0 
c++函数模板重载问题(DEVC++编译器)
[#include<iostream>
using namespace std;
int max(const int& a, const int& b)
{
    return a>b ? a : b;
}
template<typename T>
T max( constT& t1,  constT& t2)
{
    return t1 > t2 ? t1 : t2;
}
template<typename T>
T max(const T& t1, const T& t2, const T& t3)
{
    return max(max(t1,t2),t3);
}
int main()
{
    cout << max(1,2) << endl;
    cout << max(1,'3')<< endl;
    cout << max('k','e')<< endl;
//    cout << max('w','5','A')<< endl;
    return 0;
}

为什么要去掉这两个const
搜索更多相关主题的帖子: return 编译器 include 
2017-06-09 11:39



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-477773-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.017731 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved