int& function(int arr[])
In this function, arr is a pointer, and there is no way to return it back to an array. This is the same as
int& function(int* arr)
int arr[] = {...}; arr = function(arr);
Assuming the function was able to return a reference to the array, this still will not work. You cannot assign an array. At best, you can bind the result to an "X array ints reference" (using typedef, because the syntax will be very ugly otherwise):
typedef int ten_ints[10]; ten_ints& foo(ten_ints& arr) {
However, it is completely unclear what the code should achieve in your question. Any changes you make to the array in the function will be visible to the caller, so there is no reason to try to return the array or assign it back to the original array.
If you need a fixed-size array that you can assign and pass by value (with copied content), there is std::tr1::array (or boost::array ). std::vector also an option, but it is a dynamic array, so it is not an exact equivalent.
Unclebens
source share