3
我的目标是在调用for_each
时使用成员函数。所以,我没有这样的:如何绑定一个成员函数以用于std :: for_each?
for_each(an_island->cells.cbegin(),an_island->cells.cend(),std::bind(&nurikabe::fill_adjacent,this));
,但是这是我在GCC获得:
In file included from /usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/algorithm:63:0,
from prog.cpp:10:
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h: In function '_Funct std::for_each(_IIter, _IIter, _Funct) [with _IIter = std::_Rb_tree_const_iterator<std::pair<int, int> >, _Funct = std::_Bind<std::_Mem_fn<int (nurikabe::*)(std::pair<int, int>)>(nurikabe*)>]':
prog.cpp:85:103: instantiated from here
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:4185:2: error: no match for call to '(std::_Bind<std::_Mem_fn<int (nurikabe::*)(std::pair<int, int>)>(nurikabe*)>) (const std::pair<int, int>&)'
,并在VS2010,这样的:
xxresult(28): error C2825: '_Fty': must be a class or namespace when followed by '::'
全烃源代码是here
任何帮助?
我用'的std ::占位符:: _ 1'(因为,'_1'没有工作) – vivek
@vivek:对,这就是为什么我提到了它所在的命名空间的原因 - 所以你会知道如何完全限定它或使用哪个命名空间来使用using指令。 : - ] – ildjarn