1.递归调用过程中值传递
void dfs(vector<int> vt){ if(vt.size()==10){ for(auto v:vt) cout<<v<<" "; return; } vt.push_back(5); dfs(vt); } int main(){ vector<int> vt0; dfs(vt0); } #输出: 5 5 5 5 5 5 5 5 5 5
2.引用传递:
void dfs(vector<int>& vt){ if(vt.size()==10){ for(auto v:vt) cout<<v<<" "; return; } vt.push_back(5); dfs(vt); } int main(){ vector<int> vt0; dfs(vt0); for(auto v:vt0) cout<<v<<" "; } #输出: 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5