Here we pass a reference to an entire array using templates, and it compiles fine:
template <int N>
void test(int (&in)[N]){
}
int main(){
int a[2] = {1,2};
test(a);
return 0;
}
But doing the same to pass a regular array doesn't work, the template can't figure out what N
is on its own, why?
template <int N>
void test(int in[N]){
}
int main(){
int a[2] = {1,2};
test(a);
return 0;
}
error: couldn't deduce template parameter 'N'