void fun (char (&a)[2]) // 1D reference
{}
template<typename T, int SIZE>
void funT (T (&a)[SIZE]) // 1D reference
{}
int main ()
{
char c[2][2]; // 2D array
fun(c); // error
funT(c); // ok !!!??
}
I can expect that fun() gives error, but how come funT() works fine!
Is there any reference in the standard for such behavior or Is it a bug in C++ language?
Because the type of
cisn’tchar [2], it doesn’t match the firstfunction. In the template case,
Tresolves tochar [2], which meansthat the final argument type is
char (&a)[2][2]. (You can think of itas the
Tbecoming the equivalent of atypedeftochar[2], andexpand the argument type based on that.)