【发布时间】:2013-06-04 18:14:16
【问题描述】:
我收到这些错误。为什么?
在 /usr/include/c++/4.7/algorithm:63:0 包含的文件中, 来自 prog.cpp:2: /usr/include/c++/4.7/bits/stl_algo.h:在'_OIter std::transform(_IIter, _IIter, _OIter, _UnaryOperation) 的实例化中 [with _IIter = __gnu_cxx::__normal_iterator >; _OIter = std::back_insert_iterator >; _UnaryOperation = main()::]': prog.cpp:10:98: 从这里需要 /usr/include/c++/4.7/bits/stl_algo.h:4951:2: 错误:不匹配调用‘(main()::) (int&)’ prog.cpp:10:64: 注意:候选人是: 在 /usr/include/c++/4.7/algorithm:63:0 包含的文件中, 来自 prog.cpp:2: /usr/include/c++/4.7/bits/stl_algo.h:4951:2: 注意:int (*)(int, int) /usr/include/c++/4.7/bits/stl_algo.h:4951:2:注意:候选人需要 3 个参数,提供 2 个 prog.cpp:10:79: 注意: main():: prog.cpp:10:79:注意:候选人需要 2 个参数,提供 1 个
#include <algorithm>
#include <vector>
int main()
{
std::vector<int> v {1, 2, 3, 4, 5, 6};
std::vector<int> r;
std::transform(v.begin(), v.end(), std::back_inserter(r), [] (int a, int b) { return a + b; });
}
此代码应该将每对数字相加并将其放入r 向量中,但它不起作用。这是为什么呢?
【问题讨论】: