Oh, but I mean, come on. Somethimes you use static arrays and sometimes dynamic arrays. Use whichever is best suited for the situation. If you are using static arrays, then most of the reason to dismiss the use of passing by reference goes away. It can most likely also catch bugs in your code where you incorrectly assume the size of the array.
If you are using dynamic arrays, then don't pass by reference. It's that simple. But use proper tools where appropriate.
I beg to differ. It works just as it should:Quote:
and any code that uses such array references is forever incompatible with the STL, and several threads have been spent telling you such things.
Go on. Run it. It works as it should.Code:#include <string>
#include <iostream>
#include <algorithm>
#define SIZE(x) sizeof(x) / sizeof(x[0])
void foo(int (&arr)[10])
{
int bar[SIZE(arr)];
std::copy(arr, arr + SIZE(arr), bar);
for (int i = 0; i < SIZE(bar); i++)
std::cout << "bar[" << i << "]: " << bar[i] << std::endl;
}
int main()
{
int _foo[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
for (int i = 0; i < SIZE(_foo); i++)
std::cout << "_foo[" << i << "]: " << _foo[i] << std::endl;
foo(_foo);
}