Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/161.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;-在foreach中复制向量会得到;没有匹配的函数调用std::vector<;int>;::向后推(标准::向量<;int>;);_C++_C++11_Stdvector - Fatal编程技术网

C++ C++;-在foreach中复制向量会得到;没有匹配的函数调用std::vector<;int>;::向后推(标准::向量<;int>;);

C++ C++;-在foreach中复制向量会得到;没有匹配的函数调用std::vector<;int>;::向后推(标准::向量<;int>;);,c++,c++11,stdvector,C++,C++11,Stdvector,我有以下功能: std::vector<std::vector<int>> solve(int t){ std::vector<std::vector<int>> result; result.push_back(std::vector<int>(2*t,0)); //CODE TO fill up result[0] return result; } std::向量求解(int t){ std::向量

我有以下功能:

std::vector<std::vector<int>> solve(int t){
    std::vector<std::vector<int>> result;
    result.push_back(std::vector<int>(2*t,0));
    //CODE TO fill up result[0]
    return result;
}
std::向量求解(int t){
std::向量结果;
结果:推回(std::vector(2*t,0));
//填写结果的代码[0]
返回结果;
}
当我编写以下代码以获得结果时:

std::vector<std::vector<int>> results(4);
for(int t = 0; t < 4; ++t){
    std::vector<std::vector<int>> cols = solve(t);
    if(cols.size() > 0){
        for(std::vector<int> col: cols){
            results[t].push_back(col);            
        }
    }
}
std::向量结果(4);
对于(int t=0;t<4;++t){
std::向量cols=求解(t);
如果(cols.size()>0){
用于(标准::向量列:列){
结果[t],推回(col);
}
}
}
我得到以下错误:

src/pricing.cpp:33:29: error: no matching function for call to ‘std::vector<int>::push_back(std::vector<int>&)’
 results[t].push_back(col);
src/pricing.cpp:33:29:错误:调用“std::vector::push_back(std::vector&)”时没有匹配函数
结果[t],推回(col);

据我所知,基于的范围是创建
col
作为参考。我不明白的是,
push_back
能够插入
col
。为什么会发生这种情况?在
结果[t]
中插入
col
的最佳方法是什么?

col
是一个
向量

您正试图将其添加到
results
的元素中,该元素只能保存
int
s


这就是编译器告诉您的。

您正试图将
std::vector
作为元素推入
std::vector
,该元素的类型为
int
。你那句台词的意图是什么?你是对的。我不知道我怎么没看到。对于我想要的,我需要使用3 std::vector嵌套。我需要重新考虑我的策略,因为我认为这太糟糕了,如果你使用
auto
使用类型别名,那么情况不会变得更糟,真的。