call of overloaded ... is ambiguous
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行)があり、名前の競合が発生しているためです.