In this MCVE, the compiler complains that processArray
can't match the parameter list (arr
). The fix is to replace T elements[SIZE]
with T (&elements)[SIZE]
. Why do I need to do this, and under what circumstance? I wouldn't use &
to pass an array into a function ordinarily. (Only reason I thought of it is that's how C++20's new version of istream& operator>>
describes its char-array parameter.)
template <typename T, int SIZE>
void processArray(T elements[SIZE])
{
for (int i = 0; i < SIZE; ++i)
elements[i] = 2;
}
int main()
{
int arr[3];
processArray(arr);
return 0;
}