In the code below, shouldn't the function call minimum(a,a); result in
compilation error? I read in Lippman's C++ Primer 3rd Edition on page
521, the call should be ambiguous.
But on g++ (versions 3.2.3 and 3.4.2) it compiles fine and the result
shows that minimum(a,a) is resolved using minimum(T,T)
I also tried it on http://www.comeaucomputing.com/tryitout/ and got
the
same result.
So what is the correct behaviour according to the standard?
I tried reading overloading resolution rules from a few sources
(including C++ Templates and online IBM C++ reference) but I still
cannot figure out.
So can anybody tell me what the correct behaviour is according to the
latest standard? If the correct behaviour is to choose minimum(T,T)
over minimum(T,U) in this case, what's the rule which determines this
behaviour? Has it anything to do with Partial Ordering rules?
Thank you very much in advance.
#include <iostream>
using std::cout;
using std::endl;
template <class T>
T minimum(T,T)
{ cout << "minimum(T,T)" << endl; }
template <class T, class U>
int minimum(T, U)
{ cout << "minimum(T,U)" << endl; }
int main()
{
int a = 10;
unsigned int b = 20;
minimum(a,b);
minimum(a,a); // shouldn't this call ambiguous?
}