Consider a valid code:
template<size_t size>
void by_numbered_reference(int (&array)[size]);
This function accepts an array as an argument and compiler can deduce the size of it using template argument deduction.
Now it is valid (tested on Apple clang version 3.0) to define such function:
void by_reference(int (&array)[], int size);
Which (should) accept a reference to an unknown size array as an argument. Noting that int[]
and int[n]
are distinct types and generally are incompatible.
The only way which I found how to invoke this function is:
int * array;
by_reference(reinterpret_cast<int(&)[]>(*array), array_size);
- Why does the language accept a reference to an unknown size array as a valid function argument, while there is no straightforward way to define such variable?
- Are there any known use cases where this syntax is required?
- Why
void by_reference(int (*&array), int size)
should not be used instead?