I have the following set of templates:
//1
template< typename T > void funcT( T arg )
{
std::cout<<"1: template< typename T > void funcT( T arg )";
}
//2
template< typename T > void funcT( T * arg )
{
std::cout<<"2: template< typename T > void funcT( T * arg )";
}
//3
template<> void funcT< int >( int arg )
{
std::cout<<"3: template<> void funcT< int >( int arg )";
}
//4
template<> void funcT< int * >( int * arg )
{
std::cout<<"4: template<> void funcT< int *>( int * arg )";
}
//...
int x1 = 10;
funcT( x1 );
funcT( &x1 );
Can someone please explain why funcT( x1 );
calls function #3 and funcT( &x1 );
calls function #2 but not #4 as expected?
I have already read this article http://www.gotw.ca/publications/mill17.htm which says that "overload resolution ignores specializations and operates on the base function templates only". But according to this logic funcT( x1 );
should call function #1, not #3. I am confused.