Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > for_each with member fuunctions

Reply
Thread Tools

for_each with member fuunctions

 
 
Michael Hull
Guest
Posts: n/a
 
      04-20-2007
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

 
Reply With Quote
 
 
 
 
Tim Love
Guest
Posts: n/a
 
      04-20-2007
Michael Hull <(E-Mail Removed)> writes:

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


http://www-h.eng.cam.ac.uk/help/tpl/...+/mem_fun.html
might help.
 
Reply With Quote
 
 
 
 
Michael Hull
Guest
Posts: n/a
 
      04-20-2007
On 20 Apr, 15:01, (E-Mail Removed) (Tim Love) wrote:
> Michael Hull <(E-Mail Removed)> writes:
> >Hi, I know this really shouldn't be that difficult, bt I can't work it
> >out:
> > ...

>
> http://www-h.eng.cam.ac.uk/help/tpl/...+/mem_fun.html
> might help.


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

 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      04-20-2007
Michael Hull wrote:
> On 20 Apr, 15:01, (E-Mail Removed) (Tim Love) wrote:
>> Michael Hull <(E-Mail Removed)> writes:
>>> Hi, I know this really shouldn't be that difficult, bt I can't work
>>> it out:
>>> ...

>>
>> http://www-h.eng.cam.ac.uk/help/tpl/...+/mem_fun.html
>> might help.

>
> Hi,
> Thanks for the quick response, however that is not quite what I want
> to do, i want to call the method B:oA, 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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
for_each and invoking self's member pointer Kenneth Porter C++ 8 10-14-2007 12:32 AM
Using an object's member function as the action passed to for_each Belebele C++ 6 08-14-2006 03:35 PM
Why I can't use for_each to call a member function with a ostream& parameter? waitan C++ 2 02-22-2006 05:27 AM
for_each with a non const member fuction glen stark C++ 5 08-16-2005 12:37 PM
Passing pointer to member function to different member function that then calls for_each pookiebearbottom@yahoo.com C++ 8 05-24-2005 01:50 PM



Advertisments