【发布时间】:2014-07-30 08:10:39
【问题描述】:
编译这段代码时收到错误:
void Lift::AddDestFloors(const vector<Person>& persons,
vector<int>& fplan,
int lift_pos) {
for (auto &person : persons) {
int dest_flr = person.dest_floor;
if (std::find_if(fplan.begin(), fplan.end(),
[dest_flr] (const Person& person) -> bool {
return person.dest_floor == dest_flr;
}) == fplan.end()) {
InsertToMasterFlightPlan(person.dest_floor, fplan);
}
}
}
错误信息:
不匹配调用 '(Lift::AddDestFloors(const std::vector&, std::vector&, int)::__lambda0) (int&)' LiftSim 208 号线,外部位置: c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_algo.h C/C++问题
我的环境是:
- Windows 7,
- Eclipse(开普勒)
- Mingw 4.8.1
为什么会出现这个错误?
【问题讨论】:
-
大概你的意思是
std::find_if(persons.begin(), persons.end(), ...?您的 lambda 采用Person而不是int。 -
不,不是,这只是 lambda 的位置。