I don\'t understand why the array decays to a pointer in a template function.
If you look at the following code: When the parameter is forced to be a reference (fun
Because arrays can not be passed by value as a function parameter.
When you pass them by value they decay into a pointer.
In this function:
template
void f(T buff) {
T can not be char (&buff)[3]
as this is a reference. The compiler would have tried char (buff)[3]
to pass by value but that is not allowed. So to make it work arrays decay to pointers.
Your second function works because here the array is passed by reference:
template
void f1(T& buff) {
// Here T& => char (&buff)[3]