for function overloading, it is generally determined according to the function formal parameter list, so it should be the same for function templates, but for the following code
when calling function compare ("ab", "ab") reports an error, it is right to call compare ("ab", "abc"). It is not clear why int compare (const T & v1, const T & v2) does not match, because the length of the string array is inferred. Think the second one is more accurate? Can the compiler also find this difference?
-sharpinclude "pch.h"
-sharpinclude <iostream>
template <typename T>
int compare( const T& v1, const T& v2 ) {
if ( v1 < v2 ) return -1;
if (v1 > v2) return 1;
return 0;
}
template<unsigned N, unsigned M>
int compare(const char(&p)[N], const char(&p2)[M]) {
std::cout << p << " " << p2 << std::endl;
return strcmp(p, p2);
}
int main()
{
//int res2 = compare( "ab", "ab" );//
}