【发布时间】:2013-02-26 20:27:39
【问题描述】:
我有这个功能
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? -
是的,它是班级成员。我试图将其设为静态,但出现此错误:18:12:错误:在静态成员函数中无效使用成员 'TFlood::M':21:63:错误:来自此位置
标签: c++ stl operator-overloading overloading