Gianni Mariani wrote in news:bqlo18$:
>
> Does anyone know if this is supposed to work ?
>
> template <unsigned N>
> int strn( const char str[N] )
> {
> return N;
> }
This is effectivly:
template < unsigned N >
int strn( char const *str )
{
return N;
}
>
> #include <iostream>
>
> int main()
> {
> std::cout << strn( "abcd" );
> }
>
> error: no matching function for call to `strn(const char[5])'
Yup the call needs to be:
std::cout << strn< 5 >( "abcd" );
Where 5 can be any compile time integral constant you want.
template < unsigned N >
unsigned strn( char const (&str)[ N ] )
{
return N;
}
Or get creative:
template < typename T, unsigned N >
unsigned countof( T const (&array)[ N ] )
{
return N;
}
HTH.
Rob.
--
http://www.victim-prime.dsl.pipex.com/