S
SteveM
I am trying to learn C++ (taking classes at the University of
Washington) but have run across a bit of confusion with respect to
function templates. It appears that VS 2003 has a different way of
looking at things and is causing the folliwing errors when I try to
build the code excerpt below:
d:\C++ Projects\TemplatesTest\TemplatesTest\TemplatesTest.cpp(38):
error C2668: 'max' : ambiguous call to overloaded function
d:\C++ Projects\TemplatesTest\TemplatesTest\TemplatesTest.cpp(39):
error C2668: 'max' : ambiguous call to overloaded function
d:\C++ Projects\TemplatesTest\TemplatesTest\TemplatesTest.cpp(41):
error C2668: 'max' : ambiguous call to overloaded function
Now I understand from researching this that this is a known bug with
the way that Microsoft VS 2003 compilers work... my question here is
what can I do to get around this. How do I need to change the code in
order to get the results I want (according to the example) and satisfy
the restrictions being placed on the code by the compiler.
HELP!!!!!! Please
Thanks, Steve
------ Code excerpt --------------------
#include <iostream>
#include <tchar.h>
using namespace std;
//max returns the maximum of the two elements
template <class T>
T max(T a, T b)
{
return ((a > b )? a : b );
}
int _tmain(int argc, _TCHAR* argv[])
{
cout << "max((10, 15) = " << max(10, 15) << endl ;
cout << "max('k', 's') = " << max('k', 's') << endl ;
cout << "max(10.1, 15.2) = "
<< max(10.1, 15.2) << endl ;
return 0;
}
----------- End of Code excerpt ------------------------
Washington) but have run across a bit of confusion with respect to
function templates. It appears that VS 2003 has a different way of
looking at things and is causing the folliwing errors when I try to
build the code excerpt below:
d:\C++ Projects\TemplatesTest\TemplatesTest\TemplatesTest.cpp(38):
error C2668: 'max' : ambiguous call to overloaded function
d:\C++ Projects\TemplatesTest\TemplatesTest\TemplatesTest.cpp(39):
error C2668: 'max' : ambiguous call to overloaded function
d:\C++ Projects\TemplatesTest\TemplatesTest\TemplatesTest.cpp(41):
error C2668: 'max' : ambiguous call to overloaded function
Now I understand from researching this that this is a known bug with
the way that Microsoft VS 2003 compilers work... my question here is
what can I do to get around this. How do I need to change the code in
order to get the results I want (according to the example) and satisfy
the restrictions being placed on the code by the compiler.
HELP!!!!!! Please
Thanks, Steve
------ Code excerpt --------------------
#include <iostream>
#include <tchar.h>
using namespace std;
//max returns the maximum of the two elements
template <class T>
T max(T a, T b)
{
return ((a > b )? a : b );
}
int _tmain(int argc, _TCHAR* argv[])
{
cout << "max((10, 15) = " << max(10, 15) << endl ;
cout << "max('k', 's') = " << max('k', 's') << endl ;
cout << "max(10.1, 15.2) = "
<< max(10.1, 15.2) << endl ;
return 0;
}
----------- End of Code excerpt ------------------------