473,396 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

Apr 20 '07 #1
3 1191
Michael Hull <mi********@googlemail.comwrites:
>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.
Apr 20 '07 #2
On 20 Apr, 15:01, t...@eng.cam.ac.uk (Tim Love) wrote:
Michael Hull <mikehul...@googlemail.comwrites:
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

Apr 20 '07 #3
Michael Hull wrote:
On 20 Apr, 15:01, t...@eng.cam.ac.uk (Tim Love) wrote:
>Michael Hull <mikehul...@googlemail.comwrites:
>>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
Apr 20 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: trash | last post by:
I do this kindda stuff often: class CVisitableObjectVector : public std::vector<Loki::BaseVisitable<>*> { void Enable(bool enable); .... };
2
by: Alberto | last post by:
Hello, while writing a program I ran across the problem of using for_each. Although I can traverse lists with a for loop, I'd prefer to use STL's for_each. Here's my faulty code: #include...
11
by: franklini | last post by:
hello people, just wanted to say thanks again for the help in the past. i have a new problem which am wondering if any body can help me with. i have written this abtract class shape and its...
8
by: pookiebearbottom | last post by:
Ok, this is what I am trying to do. I have a member function that as a parameter accepts a pointer to a different member function. In this 2nd function, I want to iterate over an STL container...
5
by: glen stark | last post by:
Hi Everyone So, I want to use a std::for_each in the following situation: class B{ //whatever } class A{ private:
6
by: Belebele | last post by:
Suppose I want to use some object's member function as the action passed to a for_each call: class A { ... public: void foo(int ); }; A a;
3
by: Yan | last post by:
Hi, I don't seem to be able to use for_each if it should replace a 'for' loop in a method (constructor in my case) and inside that 'for' loop a class member variable is being accessed. The...
9
by: nguillot | last post by:
Hello I used to loop on a std::map<k, dto act on the data (d) like that (d being a class with setIntMember method): typedef std::map<k, dtMap; struct setIntMember { setIntMember(int j) :...
3
by: fgh.vbn.rty | last post by:
I'm having problems setting up the functors to use for_each. Here's an example: class A { public: void getName() { return name; } private: string name; };
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.