template <unsigned N>
int strn( const char str[N] )
{
return N;
}
#include <iostream>
int main()
{
std::cout << strn( "abcd" );
}
error: no matching function for call to `strn(const char[5])'
I think not since neither Comeau nor VC++ 7.1 accept it (results below), but
I must admit I am perplexed as to why. I know that in general a nontype
parameter for a function template can be deduced, but there is clearly
something special about this case. I'll be interested to follow this
thread...
Note that if you change the parameter to bre reference to array, it works...
Maybe this can hint at why the case you presented fails...
Comeau:
"ComeauTest.c", line 11: error: no instance of function template "strn"
matches the
argument list
The argument types that you used are: (const char [5])
std::cout << strn("abcd");
VC++ 7.1:
d:\visual_c++\dot_net\parameter_test\parameter_test\main.cpp(11) : error
C2784: 'int strn(const char [N])' : could not deduce template argument for
'const char [N]' from 'const char [5]'
d:\visual_c++\dot_net\parameter_test\parameter_test\main.cpp(4) :
see declaration of 'strn'