#include <iostream>
using namespace std;
int max (int a, int b)
{
return a<b?b:a;
}
template <typename T> T max (T a, T b)
{
return a<b?b:a;
}
template <typename T> T max (T a, T b, T c)
{
return max (max(a,b), c);
}
int main()
{
// The call with two chars work, flawlessly.
:: max ('c', 'b');
// This call with three chars produce the error listed below:
:: max ('c', 'b', 'a');
return 0;
}
Error:
error: call of overloaded ‘max(char&, char&)’ is ambiguous
Shouldn’t this max ('c', 'b', 'a') call the overloaded function with three arguments?
Thing is, there is already a
maxinstd, and you are sayingusing namespace std;:So your
max ('c', 'b', 'a')is called fine; the problem is inside it.I don’t know why
maxis available since you didn’t includealgorithm, but apparently it is.EDIT
If you want to keep that
usingat the top: