
Hi Chris, Chris Stankevitz wrote:
Can someone please explain why a cref is needed in the last line of the attached code snippet?
void f() { //bind(b, bind(a));//*1 bind(b, cref(bind(a)));//*2 }
Line *1 isn't doing the same thing as *2 -- see the documentation on nested binds [1]. In short, *1 is evaluating a() (which returns void), then attempting to pass that into the outer bind. I'm not sure if cref is an acceptable call to use there -- I don't know if it would always work. It would be more idiomatic to use protect: bind(b, boost::protect(bind(a))) All assuming that your actually case is more complicated than shown here, and can't be replaced with: bind(b, a); HTH, Nate [1]http://www.boost.org/doc/libs/1_52_0/libs/bind/bind.html#nested_binds