Code:
#include <iostream>
using namespace std;
template <class T> void f(T a)
{
cout << "a) using template\n";
}
template <class T> void f(T* a)
{
cout << "b) using overloaded template\n";
}
template <> void f<int*>(int* a)
{
cout << "c) using specialised template\n";
}
int main()
{
int x = 1;
int* px = &x;
f(px);
return 0;
}
If I compile and run the above program, function b) is called. For some reason, the compiler is treating function c) as a specialisation of a) and not as a specialisation of b).
However, if I change the prototype of function c) from
Code:
template <> void f<*int>(int* a)
to
Code:
template <> void f<>(int* a)
, then the compiler treats c) as a specialisation of b), and c) is called.
Can anybody explain to me why this should be the case? I would have expected function c) to have been called in the original version too. Thanks in advance for any help.