C++ - 在 foreach 中复制向量给出 "No matching function to call for std::vector<int>::push_back(std::vector<int>&)"

C++ - copying vector in foreach gives "No matching function to call for std::vector<int>::push_back(std::vector<int>&)"

我有以下功能:

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::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);            
        }
    }
}

我收到以下错误:

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);

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

colvector<int>.

您正在尝试将其添加到 results 的元素中,该元素只能包含 ints。

这就是编译器告诉你的。