hello,
i am wondering how can i do it?
i am interested in knowing what should i do to have this in-class method pointer sent to std::for_each 3rd argument?
PS for those who will look for anwser like me: here is similar problem http://bytes.com/topic/c/answers/851...using-for_each but i do not get it, i think it is a little different from presented one in this topic.
i am wondering how can i do it?
Code:
#include <stdio.h>
#include <algorithm> //std::for_each()
#include <list> //std::list<>
class CL
{
private: int times_printed;
public: CL (): times_printed(0) {};
public: void print()
{
printf("printed %d\n", ++times_printed);
};
private: std::list<int> content;
public: void add(void)
{
content.push_back(1);
content.push_back(2);
content.push_back(3);
}
public: void printAll(void)
{
std::for_each(content.begin(), content.end(), [b]CL::print[/b]);
}
};
int main(int, char**)
{
CL a;
a.add();
a.printAll();
system("PAUSE");
}
PS for those who will look for anwser like me: here is similar problem http://bytes.com/topic/c/answers/851...using-for_each but i do not get it, i think it is a little different from presented one in this topic.
Comment