Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old April 20th, 2007, 01:25 PM
Michael Hull
Guest
 
Posts: n/a
Default for_each with member fuunctions

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<Aa ) {/* */ }
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

  #2  
Old April 20th, 2007, 02:05 PM
Tim Love
Guest
 
Posts: n/a
Default Re: for_each with member fuunctions

Michael Hull <mikehulluk@googlemail.comwrites:
Quote:
>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.
  #3  
Old April 20th, 2007, 02:25 PM
Michael Hull
Guest
 
Posts: n/a
Default Re: for_each with member fuunctions

On 20 Apr, 15:01, t...@eng.cam.ac.uk (Tim Love) wrote:
Quote:
Michael Hull <mikehul...@googlemail.comwrites:
Quote:
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::DoA, not a member function in A,
which is my understanding of mem_fun

  #4  
Old April 20th, 2007, 02:35 PM
Victor Bazarov
Guest
 
Posts: n/a
Default Re: for_each with member fuunctions

Michael Hull wrote:
Quote:
On 20 Apr, 15:01, t...@eng.cam.ac.uk (Tim Love) wrote:
Quote:
>Michael Hull <mikehul...@googlemail.comwrites:
Quote:
>>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::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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 

Bookmarks

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles