If statement std::find_if如何与指针列表一起工作? 请考虑以下代码块: 1- //.h std::list<Item> itemsList;
所以,问题是:我应该如何修复谓词(块2)以使其全部工作? 我想不出来。请帮帮我。我的尝试是:If statement std::find_if如何与指针列表一起工作? 请考虑以下代码块: 1- //.h std::list<Item> itemsList;,if-statement,find,predicate,If Statement,Find,Predicate,所以,问题是:我应该如何修复谓词(块2)以使其全部工作? 我想不出来。请帮帮我。我的尝试是: struct ItemExist: public std::binary_function< Item*, int, bool > { bool operator () ( const Item *sc, const int &number ) const { return sc->orderNumber== number; } }; struct I
struct ItemExist: public std::binary_function< Item*, int, bool > {
bool operator () ( const Item *sc, const int &number ) const {
return sc->orderNumber== number;
}
};
struct ItemExist:public std::binary_函数- {
布尔运算符()(常数项*sc、常数整型和编号)常数{
返回sc->orderNumber==number;
}
};
这似乎有效,但我不确定这是正确的解决方案
3- std::list<Item>::iterator itd= std::find_if(itemList.begin(),itemList.end(),std::bind2nd( ItemExist(),orderNumber ) );
std::list<Item*> itemsList;
std::list<Item*>::iterator itd= std::find_if(itemList.begin(),itemList.end(),std::bind2nd( ItemExist(),orderNumber ) );
[C++ Error] _algobase.c(183): E2064 Cannot initialize 'const Item&' with 'Item *'
[C++ Error] _algobase.c(183): E2342 Type mismatch in parameter '__x' (wanted 'const Item&', got 'Item *')
struct ItemExist: public std::binary_function< Item*, int, bool > {
bool operator () ( const Item *sc, const int &number ) const {
return sc->orderNumber== number;
}
};