照着c++ primer上写的一个函数模板例子
出现了如下错误:
原因是std中已经有了一个名字叫min的函数(在stl_algobase.h文件的148行),导致名字冲突,
using namespace std;
template <class T>
T min(T a, T b) {
return a < b ? a : b;
}
int main() {
cout<<min(10, 32)<<endl;
cout<<min(24.1, 2.0)<<endl;
return 0;
}
出现了如下错误:
function_template.cpp: In function `int main()':
function_template.cpp:11: error: call of overloaded `min(int, int)' is
ambiguous
function_template.cpp:6: note: candidates are: T min(T, T) [with T = int]
D:/Program Files/mingw/MinGW/bin/../lib/gcc/
mingw32/3.4.2/../../../../include/c++/3.4.2/bits/stl_algobase.h:151:
note: const _Tp& std::min(const _Tp&, const _Tp&)
[with _Tp = std::streamsize]
function_template.cpp:12: error: call of overloaded `min(double, double)'
is ambiguous
function_template.cpp:6: note: candidates are: T min(T, T) [with T =
double]
D:/Program Files/mingw/MinGW/bin/../lib/gcc/
mingw32/3.4.2/../../../../include/c++/3.4.2/bits/stl_algobase.h:151:
note: const _Tp& std::min(const _Tp&, const _Tp&) [with _Tp = double]
原因是std中已经有了一个名字叫min的函数(在stl_algobase.h文件的148行),导致名字冲突,