Hello,
I am trying to use Boost::Bind to bind my function but I am getting an error as Bind cannot diffrentiate between the constructors
even though they have diffrent function signatures.
TestBind(boost::bind((&Test::process), &t1, _1));
I would highly appreciate any help.
Thanks
//Boost Includes
#include
Hi Vishal, vishal rawate wrote:
Hello,
I am trying to use Boost::Bind to bind my function but I am getting an error as Bind cannot diffrentiate between the constructors even though they have diffrent function signatures.
TestBind(boost::bind((&Test::process), &t1, _1));
I would highly appreciate any help.
Thanks
This is a problem with binding overloaded functions. See http://www.boost.org/doc/libs/1_54_0/libs/bind/bind.html#err_overloaded I typically static_cast, when I can't use a C++11 lambda. HTH, Nate
I am trying to use Boost::Bind to bind my function but I am getting an error as Bind cannot diffrentiate between the constructors even though they have diffrent function signatures.
TestBind(boost::bind((&Test::process), &t1, _1));
This is a problem with binding overloaded functions. See http://www.boost.org/doc/libs/1_54_0/libs/bind/bind.html#err_overloaded I typically static_cast, when I can't use a C++11 lambda.
Nate, as far as I can see this isn't an issue with binding to an overloaded function (because the function isn't overloaded!), it's selecting the correct constructor overload based on the return value of boost::bind. Putting a temporary TestBind::t_ProcessFunctionInt in between the creation of the TestBind object and the bind to Test::process works; it's the implicit conversion between the return value of boost::bind and the two constructor overloads which is failing. ie: this works: TestBind::t_ProcessFunctionInt fn = boost::bind((&Test::process), &t1, _1); TestBind f(fn); this doesn't: TestBind g(boost::bind((&Test::process), &t1, _1)); In other words, it's the choice between TestBind(t_ProcessFunctionInt) {} TestBind(t_ProcessFunctionShort) {} which fails Note that making the constructors explicit doesn't work: explicit TestBind(t_ProcessFunctionInt) {} explicit TestBind(t_ProcessFunctionShort) {}
Hi Steve, Steve Lorimer wrote:
Nate, as far as I can see this isn't an issue with binding to an overloaded function (because the function isn't overloaded!), it's selecting the correct constructor overload based on the return value of boost::bind.
You're absolutely right. Sorry for the bad advice. I agree with your solution. Thanks, Nate
I'm puzzled as to why making the constructors explicit doesn't work. I've posted a question on stackoverflow using std::bind / std::function (but the gist is the same) http://stackoverflow.com/questions/18939107/return-type-of-stdbind-implicitl...
participants (3)
-
Nathan Crookston
-
Steve Lorimer
-
vishal rawate