RE: [Boost-users] Base Pointer member functions failure
Alright I am now functioning in my code.
Now the hard part. Can you explain to me what I am missing.
The _1 states to use the first paramter in the first position.
Doug mentioned that there is an implicit 'this' argument.
So the bind is creating a function object
template
Okay,
Call me stupid but I can't get this to work
class Base { virtual const bool CheckFunc(const value& val ) const { return true; } }
[...]
std::find_if( vecBase.begin(), vecBase.end(), boost::bind(Base::CheckFunc, aVal ) );
Try boost::bind(&Base::CheckFunc, _1, aVal) instead. Remember that a member function has an implicit 'this' argument. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Friday 26 September 2003 06:38 pm, Mark Loew wrote:
Alright I am now functioning in my code.
Now the hard part. Can you explain to me what I am missing. The _1 states to use the first paramter in the first position.
Doug mentioned that there is an implicit 'this' argument.
That was Peter :)
So the bind is creating a function object template
With the constructor of somefunc( S (T::*p)(A) ); // declaring the pointer to the function then the operator is operator( T *p, A x ) and calls the func
Right, so the function object has two parameters, the first (which corresponds to the implicit 'this' parameter) is of type T* and the second is of type A. When using bind, think of member function pointers as having an operator() like this one, and try to forget the ugly member pointer syntax.
So in the bind I was thinking that Boost::bind( Base::CheckFunc, x )
I wrongly assumed that the T value was the variable passed in by the find_if and the second parameter was the x my second variable on my func.
With bind(), no parameter is special, including the implicit object parameter. If we have: g = boost::bind(f, _1, x) then g(y) maps to: f(y, x) in our case, 'f' is an adaptor around a member function pointer, which ends up calling: y->*CheckFunc(x) Doug
participants (2)
-
Douglas Gregor
-
Mark Loew