[INDENT][FONT=arial narrow]Hi Alli, Can anyone please help me to understand why the code below gives a compilation error. The error message is posted below the code. Thanks in Advance
Code:
#include <iostream>
template < typename T1, typename T2 > auto max(T1 a, T2 b)
{
return b < a ? a : b;
}
template < typename RT, typename T1, typename T2 > RT max(T1 a, T2 b)
{
return b < a ? a : b;
}
int main(int, char **)
{
std::cout <<::max < int >(4, 7.2);
}
Code:
a.cpp: In function 'int main(int, char**)':
a.cpp:16:32: error: call of overloaded 'max<int>(int, double)' is ambiguous
std::cout << ::max<int>(4, 7.2);
a.cpp:4:6: note: candidate: 'auto max(T1, T2) [with T1 = int; T2 = double]'
auto max (T1 a, T2 b)
a.cpp:9:4: note: candidate: 'RT max(T1, T2) [with RT = int; T1 = int; T2 = double]'
RT max (T1 a, T2 b)
The code is compiled with GCC, C++14