K
Kyle
I used following template function:
template<class Elem, int Size>
int tabSize( Elem (&tab)[Size] ) {
return Size;
}
tu deduce size and type of an array passed as parameter, but someone
proposed making the argument const (perhaps just out const correctnes),
and it become:
template<class Elem, int Size>
int tabSize( const Elem (&tab)[Size] ) {
return Size;
}
now, Comeau online compiler refuses to accept following code
int main() {
int tab[]={1,2,3,4,5};
tabSize( tab );
}
and this rises a question - why, is there some special rule regarding
arrays with function templates ??? (or perhaps comeau is wrong)
i managed to get rid of nontype template parameter and still get the
same error
template<class Elem>
void foo( const Elem (&tab)[5] ) {}
int main() {
int tab[5] = {1,2,3,4,5};
foo( tab );
}
"ComeauTest.c", line 6: error: no instance of function template "foo"
matches the
argument list
The argument types that you used are: (int [5])
foo( tab );
^
template<class Elem, int Size>
int tabSize( Elem (&tab)[Size] ) {
return Size;
}
tu deduce size and type of an array passed as parameter, but someone
proposed making the argument const (perhaps just out const correctnes),
and it become:
template<class Elem, int Size>
int tabSize( const Elem (&tab)[Size] ) {
return Size;
}
now, Comeau online compiler refuses to accept following code
int main() {
int tab[]={1,2,3,4,5};
tabSize( tab );
}
and this rises a question - why, is there some special rule regarding
arrays with function templates ??? (or perhaps comeau is wrong)
i managed to get rid of nontype template parameter and still get the
same error
template<class Elem>
void foo( const Elem (&tab)[5] ) {}
int main() {
int tab[5] = {1,2,3,4,5};
foo( tab );
}
"ComeauTest.c", line 6: error: no instance of function template "foo"
matches the
argument list
The argument types that you used are: (int [5])
foo( tab );
^