for_each with member fuunctions

M

Michael Hull

Hi, I know this really shouldn't be that difficult, bt I can't work it
out:


class A
{
public:
/* Class Definition*/
};


class B
{
list< boost::shared_ptr<A> > aList;
public:
void DoA( boost::shared_ptr<A> a ) {/* */ }
void DoAll()
{

list<A>::iterator it;
for(it = aList.begin();it !=aList.end();it++)
DoA(*it);
}
};


now i have code similar to this, but I am trying to replace it with a
for_each line.

for_each( aList.begin(),aList.end(), ????)

And this is where I am having a problem, if DoA were a free function,
it would be no problem, i could use ptr_fun, but I can't work out how
to associate the 'this' instance with the member function to create a
functor!
Many thanks in advance

Mike
 
V

Victor Bazarov

Michael said:
Hi,
Thanks for the quick response, however that is not quite what I want
to do, i want to call the method B::DoA, not a member function in A,
which is my understanding of mem_fun

Take a look at 'mem_fun1' and 'bind1st'. You will probably need to
bind the 'this' to 'mem_fun1'.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top