Can anyone explain why the class member functions need their address taken when used in a boost::lambda::bind inside the class? e.g. vector<int> v; MyClass theClass; for_each(v.begin(), v.end(), bind(MyClass::DoSomething, &theClass, _1)); //The above compiles fine, but. class MyClass { public: void DoSomething(const int& i) { . } void Go() { for_each(myInts.begin(), myInts.end(), /*--------------------->*/ bind(MyClass::DoSomething, this, _1)); } vector<int> myInts; }; The above code does not compile. The marked line needs to be: bind(&MyClass::DoSomething, this, _1)); Why? Thanks. - Sean
On Tue, 29 Mar 2005 22:30:43 -0500, Sean DeNigris
Can anyone explain why the class member functions need their address taken when used in a boost::lambda::bind inside the class?
Are you sure MyClass::DoSomething is legal C++ for getting a pointer to a member function? A google for "C++ member function pointer" lead me to http://linuxquality.sunsite.dk/articles/memberpointers/ which states the following: "For regular function pointers, it is optional to use the address-of operator & when taking the address of a function, but it is required for taking the address of member functions. g++ will compile source that leaves it out, but emits a warning." - Scott McMurray
participants (2)
-
me22
-
Sean DeNigris