Boost logo

Boost Users :

From: Carl Waldbieser (yg-boost-users_at_[hidden])
Date: 2003-07-15 22:05:05


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


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