473,386 Members | 1,693 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,386 software developers and data experts.

for_each(blah, blah, PROBLEM), need some help :)

7
Hi,

im having trouble getting the syntax right for this situation, ive searched everywhere and all the instructions of found im having trouble relating to what im trying to achieve.

Expand|Select|Wrap|Line Numbers
  1. class Foo {
  2.  public:
  3.   void blah(void);
  4.   void memFunc(ptr* arg);
  5.   list<ptr*> myList;
  6. };
  7.  
  8. void Foo::blah(void) {
  9.  for_each(myList.begin(), myList.end(), &Foo::memFunc);
  10. }
  11.  
  12. void Foo::memFunc(ptr* arg) {
  13.  //do stuff with arg and this
  14. }
  15.  
  16.  
ie. i want to apply the memFunc from the instance of Foo that is doing blah() to each of that instance's myList members.

but i dont know how to tell the compiler that i want the instance that is having blah called to be the instance that applies its memFunc. i couldnt get "this" to work and i was crashing the compiler with some of my attempts hehe

currently it just wont compile with the error message:
c:\program files\microsoft visual studio 8\vc\include\algorithm(29) : error C2064: term does not evaluate to a function taking 1 arguments
source.cpp(##) : see reference to function template instantiation '_Fn1 std::for_each<std::list<_Ty>::_Iterator<_Secure_va lidation>,void(__thiscall Foo::* )(ptr *)>(_InIt,_InIt,_Fn1)' being compiled
with
[
_Fn1=void (__thiscall Foo::* )(ptr *),
_Ty=ptr *,
_Secure_validation=true,
_InIt=std::list<ptr *>::_Iterator<true>
]

Windows, Visual C++ 2005 Express

thanks
Apr 5 '07 #1
1 1660
vusak
7
well i think i may have discovered the solution myself hehe

Expand|Select|Wrap|Line Numbers
  1. for_each(myList.begin(), myList.end(), std::bind1st(std::mem_fun(&Foo::memFunc), this));
seems to be working
Apr 5 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Mariusz Sakowski | last post by:
Can someone translate this code to a C++? repeat file.Read(bufor, 1); for p := 1 to KeyCount do begin buf := buf xor Keys; end; targetFile.Write(bufor, 1); until file.Size = file.Position;
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...
3
by: Tony Johansson | last post by:
Hello! I have some problem with STL. I have two classes called Handle which is a template class and Integer which is not a template class. The Integer class is just a wrapper class for a...
6
by: Michal Wyrebski | last post by:
Hello, I'm new in this group and I don't know if my questions are too silly, but I'm intermediate programmer and don't have enought experience. Please be charitable. I don't know how to write...
1
by: Capstar | last post by:
Hi NG, I have a question on std::for_each. I try to use this in combination with std::bind2nd to call a method of all functions in a container (std::set or std::map) and pass that method the...
9
by: Mehturt | last post by:
Hi.. I have came across this problem, I don't know why it does not work.. Thanks for your explanations.. m #include <map> #include <algorithm> struct fo {
9
by: Chris Roth | last post by:
I have a vector of vectors: vector< vector<double v; and have initialized it with: v( 5 ); as I know I will have 5 columns of data. At this point, I read text file data into each of the the...
13
by: Sarath | last post by:
What's the advantage of using for_each than the normal iteration using for loop? Is there any 'tweak' to use stream objects as 'Function' parameter of for_each loop. Seems copy function can do...
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) :...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.