K
Kaba
Hi,
In the following is a short code snippet concerning the overload
resolution with function templates. Which function should be chosen in
this case (i.e. what should the program return)?
template <typename Type>
class Base {};
template <typename Type>
class A : public Base<Type> {};
template <typename Type>
int f(const Base<Type>& that) {return 0;}
template <typename Type>
int f(const Type& that) {return 1;}
int main()
{
A<int> a;
return f(a);
}
I am surprised to see that both Visual Studio 2008 and Comeau C++ both
choose the unrestricted template (return 1). I'd argue that the other
one containing Base<Type> parameter is more specialized. What is going
on?
In the following is a short code snippet concerning the overload
resolution with function templates. Which function should be chosen in
this case (i.e. what should the program return)?
template <typename Type>
class Base {};
template <typename Type>
class A : public Base<Type> {};
template <typename Type>
int f(const Base<Type>& that) {return 0;}
template <typename Type>
int f(const Type& that) {return 1;}
int main()
{
A<int> a;
return f(a);
}
I am surprised to see that both Visual Studio 2008 and Comeau C++ both
choose the unrestricted template (return 1). I'd argue that the other
one containing Base<Type> parameter is more specialized. What is going
on?