相关疑难解决方法(0)

C++向量,返回与参数

可能重复:
如何在C++中"返回一个对象"

我想知道以下三种方法之间是否存在差异:

void FillVector_1(vector<int>& v) {
    v.push_back(1); // lots of push_backs!
}

vector<int> FillVector_2() {
    vector<int> v;
    v.push_back(1); // lots of push_backs!
    return v;
}

vector<int> FillVector_3() {
    int tab[SZ] = { 1, 2, 3, /*...*/ };
    return vector<int>(tab, tab + SZ);
}
Run Code Online (Sandbox Code Playgroud)

c++ stl vector

10
推荐指数
4
解决办法
7371
查看次数

标签 统计

c++ ×1

stl ×1

vector ×1