#include <iostream>
#include <cstring>
using namespace std;
template<typename Type>
Type max(Type T1,Type T2)
{
return (T1>T2 ? T1:T2);
}
typedef const char* PCC;
template<> PCC max<PCC>(PCC s1,PCC s2)
{
return (strcmp(s1,s2)>0 ? s1:s2);
}
int main()
{
int i=max(0,5);
const char *p=max("hello","world");
cout<<"i: "<<i<<endl;
cout<<"p: "<<p<<endl;
return 0;
}
编译器报错;
d:\c++\exercise 10_8\exercise 10_8.cpp(22) : error C2668: 'max' : ambiguous call to overloaded function
d:\c++\exercise 10_8\exercise 10_8.cpp(7): could be 'Type max<int>(Type,Type)'
with
[
Type=int
]
e:\program files\microsoft visual studio 8\vc\include\xutility(2936): or 'const _Ty &std::max<int>(const _Ty &,const _Ty &)'
with
[
_Ty=int
]
while trying to match the argument list '(int, int)'
d:\c++\exercise 10_8\exercise 10_8.cpp(23) : error C2668: 'max' : ambiguous call to overloaded function
d:\c++\exercise 10_8\exercise 10_8.cpp(14): could be 'PCC max<PCC>(PCC,PCC)'
e:\program files\microsoft visual studio 8\vc\include\xutility(2936): or '_Ty (&std::max<const char[6]>(_Ty (&),_Ty (&)))'
with
[
_Ty=const char [6]
]
while trying to match the argument list '(const char [6], const char [6])'
生成日志保存在“file://d:\C++\exercise 10_8\Debug\BuildLog.htm”
exercise 10_8 - 2 个错误,0 个警告
========== 生成: 0 已成功, 1 已失败, 0 最新, 0 已跳过 ==========
我不知道哪里错了,希望高手指教,谢谢啊!