+ 3
If I do not remove the "const", I receive an error massage: explicit specialization 'const char *.....' WHY?
const T min(const T x, const T y) { return ((x < y) ? x : y); } template<> const char* min(const char* s1, const char* s2) { return ((std::strcmp(s1, s2) < 0) ? s1 : s2); }
2 Respostas
+ 3
Because const char* is not the correct return type.
The const in front of the T applies to the whole type, where T is const char*.
const T would then be const char* const. ( a constant pointer that is pointing to a constant char )
Therefore the correct return type is const char* const.
----
Just as an FYI:
Function overloading should be preferred over function specialization.
http://www.gotw.ca/publications/mill17.htm
+ 2
Thanks for answer, now I've got it.