Return an array in c++

前端 未结 11 2108
半阙折子戏
半阙折子戏 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:39

    Use std:: vector like this.

    std::vector function(const std::vector& arr)
    {
      return arr;
    }
    

    An array like

    int arr[] = {...};
    

    is not useful to be returned from a function because its not able to copy itself.

提交回复
热议问题