Return an array in c++

前端 未结 11 2220
半阙折子戏
半阙折子戏 2021-01-02 12:14

Suppose I have an array

int arr[] = {...};
arr = function(arr);

I have the function as

 int& function(int arr[])
 {
//         


        
11条回答
  •  感动是毒
    2021-01-02 12:34

    You're returning a reference to an int, not a reference to an array.

    You want :

    (int*)& function(int arr[])
    {
         /// rest of the code
         return arr;
    }
    

    That said, as others already said, that's not good practice.

提交回复
热议问题