How do I get the for_each algorithm to use the objects function (line 17)?
Code:1 #include <iostream> 2 #include <list> 3 4 class MyClass 5 { 6 public: 7 MyClass(); 8 ~MyClass(); 9 std::list<int> l; 10 void Print(int i); 11 }; 12 13 MyClass::MyClass() 14 { 15 for (int a=0;a<11;++a) 16 l.push_back(a); 17 std::for_each(l.begin(),l.end(),Print); 18 } 19 MyClass::~MyClass() 20 { 21 } 22 void MyClass::Print(int i) 23 { 24 std::cout<<i<<std::endl; 25 } 26 27 28 int main(int argc,char* argv[]) 29 { 30 MyClass mc; 31 return 0; 32 }



LinkBack URL
About LinkBacks



I used to be an adventurer like you... then I took an arrow to the knee.