Again thank you so much for the help.
Jodie wrote:
Hi All,
I have the following program:
emplate <class T>
T max(T a, T b)
{
return a > b ? a : b ;
}
void main()
{
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 ;
}
Had complier errror message as below:
Error 1 error C2668: 'max' : ambiguous call to overloaded
function d:\\learnc.cpp 35
I couldn't figure out what is the problem. Could you please help.
The problem is that you've defined a function with the same name as a
standard library function, and you've put in a "using namespace std;" (which
you didn't show).
You can either:
1. Remove "using namespace std;" and explicitly qualify your references to
cout (e.g. std::cout), or
2. Name your templated max function something else, such as my_max.
-cd