I've got this for loop:
std::vector<itemPtr>::iterator it;
for(it=items.begin(); it!=items.end(); ++it)
{
investigators.addToLeaderInventory(*it);
}
I'd like to convert it to something like this:
std::for_each(items.begin(), items.end(), investigators.addToLeaderInventory);
However, that line doesn't compile. g++ shows me this:
error: no matching function for call to
‘for_each(__gnu_cxx::__normal_iterator<std::tr1::shared_ptr<yarl::item::Item>*,
std::vector<std::tr1::shared_ptr<yarl::item::Item>,
std::allocator<std::tr1::shared_ptr<yarl::item::Item> > > >,
__gnu_cxx::__normal_iterator<std::tr1::shared_ptr<yarl::item::Item>*,
std::vector<std::tr1::shared_ptr<yarl::item::Item>,
std::allocator<std::tr1::shared_ptr<yarl::item::Item> > > >, <unresolved overloaded
function type>)’
/usr/include/c++/4.4/bits/stl_algo.h:4194: note: candidates are: _Funct
std::for_each(_IIter, _IIter, _Funct) [with _IIter =
__gnu_cxx::__normal_iterator<std::tr1::shared_ptr<yarl::item::Item>*,
std::vector<std::tr1::shared_ptr<yarl::item::Item>,
std::allocator<std::tr1::shared_ptr<yarl::item::Item> > > >, _Funct = void
(yarl::party::Party::*)(yarl::itemPtr)]
Hard to read, to say the least. I imagine the solution is pretty simple, but I can't figure out what g++ is complaining about. The signature of investigators.addToLeaderInventory()
is this:
void ClassName::addToLeaderInventory(itemPtr item);
which should work with a for_each
, shouldn't it? What should I change?