c++复习Return Passing

来源:互联网 发布:js跳转到指定url 编辑:程序博客网 时间:2024/06/06 05:09

In C++, there are several different mechanisms for returning from a function. The most straightforward mechanism to use is return-by-value.

vector<int>partialSum(const vector<int>&arr){    vector<int>result(arr.size());    result[0]=arr[0];    for(int i=1;i<arr.size();++i)        result[i]=result[i-1]+arr[i];    return result;}vector<int>vec;vector<int>sums=partialSum(vec);//copy in old C++; move in c++11;

return-by-constant-reference; In C++11, objects can define move semantics that can be employed when return-by-value is seen;

functions can use return-by-reference.


我自己写的小网站www.caozhicong.com
原创粉丝点击