Help with boost functional

The following code produces errors when compiled on MSVC6: ************* Start test.cpp ************************ #include <iostream> #include "boost/functional.hpp" struct Foo { int operator()(int x) const {return x+1;} }; typedef class boost::const_mem_fun1_t<int,struct Foo,int> FType; int main() { Foo foo; std::cout << foo(1) << "\n"; //This works //std::cout << boost::bind2nd<FType>(boost::mem_fun(&Foo::operator ()), 7)(&foo) << "\n"; //This does not. std::cout << boost::bind2nd(boost::mem_fun(&Foo::operator ()), 7)(&foo) << "\n"; return 0; } ****************** end test.cpp ******************* The error is as follows: --------------------Configuration: mem_fun_test - Win32 Debug-------------------- Compiling... test.cpp C:\Documents and Settings\waldbcar.WALDBCAR\My Documents\My Projects\VC\test\mem_fun_test\test.cpp(20) : error C2782: 'class boost::binder2nd<Operation> __cdecl boost::bind2nd(Operation &,const Operation &)' : template parameter 'Operation' is ambig uous could be 'int' or 'class boost::const_mem_fun1_t<int,struct Foo,int>' C:\Documents and Settings\waldbcar.WALDBCAR\My Documents\My Projects\VC\test\mem_fun_test\test.cpp(20) : error C2782: 'class boost::binder2nd<Operation> __cdecl boost::bind2nd(const Operation &,const Operation &)' : template parameter 'Operation' is ambiguous could be 'int' or 'class boost::const_mem_fun1_t<int,struct Foo,int>' Error executing cl.exe. test.obj - 2 error(s), 0 warning(s) I am just not seeing where the ambiguity is coming from. The commented out line will actually compile and run as I expected, but I can't figure out why the compiler can't deduce the template argument. Any ideas? Thanks in Advance! Carl Waldbieser waldbie[at-sign-here]attglobal.net

//This works //std::cout << boost::bind2nd<FType>(boost::mem_fun(&Foo::operator ()), 7)(&foo) << "\n";
I strongly suggest that you use: boost::bind(&Foo::operator(), _1, 7)(&foo);
//This does not. std::cout << boost::bind2nd(boost::mem_fun(&Foo::operator ()), 7)(&foo) << "\n";
I am just not seeing where the ambiguity is coming from. The commented out line will actually compile and run as I expected, but I can't figure out why the compiler can't deduce the template argument. Any ideas?
Thanks in Advance!
You want to use Boost.Bind. Really. Most of boost/functional.hpp should probably be deprecated (along with boost/compose.hpp), because Bind is superior in almost every aspect. Doug
participants (2)
-
Carl Waldbieser
-
Douglas Gregor