On Thu, Apr 12, 2012 at 3:02 PM, Kaz
wrote: Hi All, I came across this strange error. Binding of overloaded member functions works with boost bind, but not with boost lambda bind. Here is the example
Following builds and works fine
#include "boost/function.hpp" #include "boost/bind.hpp"
class Operations { public: void Fun1( int i ){ std::cout<<"\nfunction with one arg\n"; } void Fun1( int i, double d) {std::cout<<"\nfunction with two args\n"; } }; ----------------------- int main() { Operations op; typedef boost::function
fptr; fptr func1 = boost::bind(&Operations::Fun1,&op,1); fptr func2 = boost::bind(&Operations::Fun1,&op, 1, 2.2 ); return 0; } I'm kind of surprised this works. Perhaps bind infers the correct arity given the number of parameters, and based on the arity, the compiler is able to deduce which overload of Fun1 you want. In any case, it probably wouldn't work if you overloaded Fun1 on argument type only. Correct. Boost.Bind is deducing the correct function pointer. Your assumption is correct that when overloading only on one argument, it fails. I was as surprised as you are, however, this works for phoenix too. If
On 04/13/2012 03:07 AM, Jeffrey Lee Hellrung, Jr. wrote: the OP really needs more functionality than provided by bind, he should go with phoenix.
------------------------ While following Does not compile
int main() { using namespace boost::lambda; Operations op; typedef boost::function
fptr; fptr func1 = bind(&Operations::Fun1,&op,1); fptr func2 = bind(&Operations::Fun1,&op, 1, 2.2 ); return 0 } -------------------------
This spits out massive error, as shown below. I think gist of which is it can't figure out which function to instantiate, when using lambda bind. Can some body please point out what am I missing here ?
I'm guessing that, unlike boost::bind, boost::lambda::bind is not overloaded directly for member function pointers. In any case, you're probably asking for trouble with expressions like&Operations::Fun1 when Fun1 is overloaded :/
(Sorry for long email, I didn't wanted to clutter the email with this error message, bu thought most of you will figure it out just from looking at it.). Any help will be appreciated, and thanks in advance. Kaz
boostFunctionAndBind.cpp: In function ‘int main()’: boostFunctionAndBind.cpp:61:45: error: no matching function for call to ‘bind(<unresolved overloaded function type>, Operations*, int)’ boostFunctionAndBind.cpp:61:45: note: candidates are:
[...snip candidates...]
- Jeff
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users