|

楼主 |
发表于 2003-9-27 15:47:10
|
显示全部楼层
- #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;
- }
复制代码
就是这个模块,
错误提示:
- 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]
复制代码 |
|