|
程序错在哪里?
谢谢。
- #include <iostream>
- using namespace std;
- template <class T>
- T max (T x, T y) { //
- return (x>y)? (x):(y); //这个表情本来是一个冒号和(
- }
- int main () {
- int x=3, y=4;
- double a=1.1, b=3.4;
- cout<<max(x, y)<<endl; //
- cout<<max(a, b)<<endl;
- }
- /*
- [root@localhost c08]# g++ p149.cpp -o p149
- p149.cpp: In function `int main()':
- p149.cpp:12: error: call of overloaded `max(int&, int&)' is ambiguous
- p149.cpp:5: error: candidates are: T max(T, T) [with T = int]
- /usr/include/c++/3.3.2/bits/stl_algobase.h:169: error: const
- _Tp& std::max(const _Tp&, const _Tp&) [with _Tp = int]
- p149.cpp:13: error: call of overloaded `max(double&, double&)' is ambiguous
- p149.cpp:5: error: candidates are: T max(T, T) [with T = double]
- /usr/include/c++/3.3.2/bits/stl_algobase.h:169: error: const
- _Tp& std::max(const _Tp&, const _Tp&) [with _Tp = double]
- (i-search)`':
- */
复制代码 |
|