|
楼主 |
发表于 2003-9-26 02:13:11
|
显示全部楼层
晚上有编译了一个小template,
[code:1]#include <iostream>
using namespace std;
template<class T>
T max(T a,T b)
{
return a>b?a:b;
}
int main()
{
cout<<"Max(3,5) is"
<<max(3,5)<<endl;
cout<<"Max('3','5') is"
<<max('3','5')<<endl;
}
[/code:1]
错误信息
[code:1]tmp.cpp: In function `int main()':
tmp.cpp:12: call of overloaded `max(int, int)' is ambiguous
tmp.cpp:6: candidates are: T max(T, T) [with T = int]
/usr/include/c++/3.2.2/bits/stl_algobase.h:169: const _Tp&
std::max(const _Tp&, const _Tp&) [with _Tp = int]
tmp.cpp:13: call of overloaded `max(char, char)' is ambiguous
tmp.cpp:6: candidates are: T max(T, T) [with T = char]
/usr/include/c++/3.2.2/bits/stl_algobase.h:169: const _Tp&
std::max(const _Tp&, const _Tp&) [with _Tp = char]
[/code:1]
哪个能帮我解释一下啦,错误的第三句和第五句,到底是怎么回事啊,解释一下,
还有第一句,是不是我的编译器的问题啊? |
|