I just downloaded DJGPP 2.03 and I wanted to test it on something
simple. Unfortunately, I chose something I know little about -- C++
templates. (The code is practically copied directly from MS's own
webpages.) The following compiles in VS6 with 0 errors and warnings,
but the DJGPP compile gives errors indicating that the call to "min"
in the main program is ambiguous (errors are shown below the code).
Have I implemented the template incorrectly? Have I used gxx
incorrectly? Is VS lax when it comes to picking out problems? (I
notice it doesn't warn me that argc and argv are never used.)
Anyway, the code and DJGPP's error messages...
----------
/* TEST.CPP -
*/
#include<iostream>
#include<string>
using namespace std;
template <class T>
T min (T a, T b)
{
return (a < b) ? a : b;
}
int main (int argc, char *argv[])
{
cout << "min(5, 10) is: " << min(5, 10) << endl;
cout << "min(2.5, 1.0) is: " << min(2.5, 1.0) << endl;
cout << "min('A', 'a') is: " << min('A', 'a') << endl;
return 0;
} // end main
----------
C:\SRC\CPP> gxx test.cpp -o test.exe
test.cpp: In function `int main(int, char**)':
test.cpp:27: error: call of overloaded `min(int, int)' is ambiguous
test.cpp:18: error: candidates are: T min(T, T) [with T = int]
C:/APPS/DOS/DJGPP/lang/cxx/3.32/bits/stlalgobase.h:149: error:
const _Tp& std::min(const _Tp&, const _Tp&) [with _Tp = int]
test.cpp:28: error: call of overloaded `min(double, double)' is
ambiguous
test.cpp:18: error: candidates are: T min(T, T) [with T = double]
C:/APPS/DOS/DJGPP/lang/cxx/3.32/bits/stlalgobase.h:149: error:
const _Tp& std::min(const _Tp&, const _Tp&) [with _Tp = double]
test.cpp:29: error: call of overloaded `min(char, char)' is ambiguous
test.cpp:18: error: candidates are: T min(T, T) [with T = char]
C:/APPS/DOS/DJGPP/lang/cxx/3.32/bits/stlalgobase.h:149: error:
const _Tp& std::min(const _Tp&, const _Tp&) [with _Tp = char]
----------
db