Why, in the below, is the call to an instantiation of bar
not ambiguous, while the non-template overloaded function foo
is ambiguous. It is the same for nullptr
instead of NULL
#include <iostream>
template<typename T>
void bar (T*)
{
std::cout << "bar(T*)" << std::endl;
}
template<typename T>
void bar (typename T::value_type *)
{
std::cout << "bar(T::value_type*)" << std::endl;
}
struct A
{
using value_type = int;
};
void foo (A::value_type*)
{
std::cout << "foo(A::value_type *)" << std::endl;
}
void foo (A*)
{
std::cout << "foo(A *)" << std::endl;
}
int main ()
{
bar<A> (NULL);
foo (NULL); // ambigous
}
EDIT: To be clear. I expect the foo
overload to be ambiguous. I don't understand why the bar
overloads generated when I instantiate bar<A>
are not equally ambiguous.