我有這個功能使用比較功能
std::vector <std::vector <int> > puddles;
std::set <int> is_checked;
size_t M, N;
bool v_compare(int a, int b){
return puddles[(a-a%M)/M][a%M] < puddles[(b-b%M)/M][b%M];
}
,我想找到其對應於puddles
最小值設定的元素(我用i*M+j
作爲集的關鍵)。所以,我想用我的功能作謂語的min_element
close(*std::min_element(is_checked.begin(), is_checked.end(), v_compare));
,但我得到這個錯誤
:113:82: error: no matching function for call to 'min_element(std::set<int>::iterator, std::set<int>::iterator, <unresolved overloaded function type>)'
:113:82: note: candidates are:
/usr/include/c++/4.6/bits/stl_algo.h:6173:5: note: template<class _FIter> _FIter std::min_element(_FIter, _FIter)
/usr/include/c++/4.6/bits/stl_algo.h:6201:5: note: _FIter std::min_element(_FIter, _FIter, _Compare) [with _FIter = std::_Rb_tree_const_iterator<int>, _Compare = bool (TFlood::*)(int, int)]
/usr/include/c++/4.6/bits/stl_algo.h:6201:5: note: no known conversion for argument 3 from '<unresolved overloaded function type>' to 'bool (TFlood::*)(int, int)'
是否有v_compare類的成員?它是否在標記爲'static'的類中聲明瞭它? – aschepler 2013-03-11 15:29:00
是的,它是班級成員。我試圖使它靜態,但我有這個錯誤:18:12:錯誤:無效使用成員'TFlood :: M'在靜態成員函數 :21:63:錯誤:從這個位置 – arkhy 2013-03-11 15:35:38