Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost::Bind Problem
From: Steve Lorimer (steve.lorimer_at_[hidden])
Date: 2013-09-20 23:29:20


>

> > 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) {}



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net