The Example is taken from the < c++ primer > ( 4th Edtion ) by Stanley B. Lippman, and it resides in P681. He says : There are an overloaded function set which contains both ordinary overloaded functions as well as function templates.
And here are two of them:
1 2
|
template < typename T > int compare( const T& , const T& );
int compare( const char*, const char* );
|
He says the following call will run the template version.
1 2 3
|
char ch_arr1[] = "world", ch_arr2[] = "hi";
char * p1 = ch_arr1, *p2 = ch_arr2 ;
compare( p1, p2 );
|
Well, he also says the reason is that the function template is an exact match with binding char* to T while the plain version still requires a conversion from char* to const char*.
This confuse me!
As he says, the function template binds char* to T, so the instantiation of the function template should be
int compare( const char* & , const char* & )
, not
int compare( char* , char* )
right?
If it is the case, then the viable functions should be
int compare( const char* &, const char* & )
which is an instantiation of the function template , and
int compare( const char*, const char* )
which is the ordinary function, so the template version needs an extra binding apart from the conversion from char* to const char*, that is to say, the ordinary function should be a better match, Right?
Well, I test it on my machine , it turns out what Lippman says is the case, but i really don't understand, does what i said is unreasonable?