关于函数模板问题 为什么一直报错??
c++吧
全部回复
仅看楼主
level 5
.h
template <class T>
T min(T a,T b)
{
     return a<b?a:b;
}
.cpp
#include<iostream>
#include"1.h"
int main()
{
     using namespace std;
     min<int>(2,5);
     min(a.b);
     cout<<""<<<<endl;
}
2011年04月08日 08点04分 1
level 5
1>e:\vs\lesson 3\lesson 3\template.cpp(6) : error C2668: “min”: 对重载函数的调用不明确
1>         e:\vs\lesson 3\lesson 3\1.h(2): 可能是“T min<int>(T,T)”
1>         with
1>         [
1>             T=int
1>         ]
1>         e:\vs2008\vc\include\xutility(3371): 或        “const _Ty &std::min<int>(const _Ty &,const _Ty &)”
1>         with
1>         [
1>             _Ty=int
1>         ]
1>         试图匹配参数列表“(int, int)”时
1>e:\vs\lesson 3\lesson 3\template.cpp(7) : error C2065: “a”: 未声明的标识符
1>e:\vs\lesson 3\lesson 3\template.cpp(7) : error C2228: “.b”的左边必须有类/结构/联合
1>         类型是“'unknown-type'”
1>e:\vs\lesson 3\lesson 3\template.cpp(7) : error C2780: “T min(T,T)”: 应输入 2 个参数,却提供了 1 个
1>         e:\vs\lesson 3\lesson 3\1.h(2) : 参见“min”的声明
1>e:\vs\lesson 3\lesson 3\template.cpp(7) : error C2780: “const _Ty &std::min(const _Ty &,const _Ty &,_Pr)”: 应输入 3 个参数,却提供了 1 个
1>         e:\vs2008\vc\include\xutility(3379) : 参见“std::min”的声明
1>e:\vs\lesson 3\lesson 3\template.cpp(7) : error C2780: “const _Ty &std::min(const _Ty &,const _Ty &)”: 应输入 2 个参数,却提供了 1 个
1>         e:\vs2008\vc\include\xutility(3371) : 参见“std::min”的声明
1>e:\vs\lesson 3\lesson 3\template.cpp(8) : error C2059: 语法错误 : “<<”
1>生成日志保存在“file://e:\VS\lesson 3\lesson 3\Debug\BuildLog.htm”
1>lesson 3 - 7 个错误,0 个警告
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========

2011年04月08日 08点04分 2
level 1
.cpp
#include<iostream>
using namespace std;
#include"1.h"
int main()
{
     min(2,5);
     cout<<""<<<<endl;
}
2011年04月08日 08点04分 3
level 5
楼上什么意思??
2011年04月08日 08点04分 4
level 5
min(a, b);
2011年04月08日 09点04分 5
level 7
楼主真的会函数的调用么?
先把函数回头看看吧。
2011年04月08日 10点04分 6
level 12
min与标准库<algorithm>中的std::min重名,<iostream>可能包含了min(VS2010就是这样)
其他的同LSS
2011年04月08日 10点04分 7
level 5
谢谢楼上  
2011年04月08日 13点04分 8
1