我尝试使用 find_if 通过其值在地图中查找键。但我无法编译代码:
struct IsCurrency : binary_function<pair<const Bill::CodeCurrency, string>, string, bool> {
bool isCurrency(const pair<const Bill::CodeCurrency, string>& element, const string& expected) const {
return element.second == expected;
}
};
string currency = "RUB";
map<Bill::CodeCurrency, string>::const_iterator my_currency = find_if(Bill::currency_code_map().begin(), Bill::currency_code_map().end(), bind2nd(IsCurrency(), currency)); /// <--- ERROR IS HERE
Bill::CodeCurrency
是一个枚举。
错误:
/usr/include/c++/4.7/bits/stl_algo.h:4490:41: required from ‘_IIter std::find_if(_IIter, _IIter, _Predicate) [with _IIter = std::_Rb_tree_const_iterator<std::pair<const Bill::CodeCurrency, std::basic_string<char> > >; _Predicate = std::binder2nd<IsCurrency>]’
../src/money_acceptor/itl_bill_acceptor.cpp:182:121: required from here
/usr/include/c++/4.7/backward/binders.h:155:29: error: no match for call to ‘(const IsCurrency) (const first_argument_type&, const second_argument_type&)’
你能帮我确定这里的错误是什么吗?