2012-04-17 13 views
5

que tenía este edificio código y funcionando perfectamente:Pasar de impulso :: unen a std :: bind: Error de compilación

boost::function<void(string)> bar = boost::bind(&Bar::BarHandler, this, _1); 

//Somewhere else in Bar.cpp 
void Bar::BarHandler(std::string message){ 
    //Do stuff 
} 

Cuando felizmente cambiado boost por std en el código anterior, empecé a recibir este error (mi compilador es Visual Studio 2010 SP1):

c:\program files\microsoft visual studio 10.0\vc\include\xxpmfcaller(42): error C2664: 

'void (std::string)' : cannot convert parameter 1 from 'boost::arg<I>' to 'std::string' 
1>   with 
1>   [ 
1>    I=1 
1>   ] 
1>   No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called 
1>   c:\program files\microsoft visual studio 10.0\vc\include\xxpmfcaller(52) : see reference to function template instantiation '_Ret std::tr1::_Pmf_caller2<_Ret,_Arg0>::_Call_pmf<_Pmf,_Ty,_Farg1>(volatile const void *,_Pmf,_Farg0 &,_Farg1 &)' being compiled 
1>   with 
1>   [ 
1>    _Ret=_Rx, 
1>    _Arg0=BarLib::Bar, 
1>    _Pmf=void (__thiscall BarLib::Bar::* const)(std::string), 
1>    _Ty=BarLib::Bar *, 
1>    _Farg1=boost::arg<1>, 
1>    _Farg0=BarLib::Bar * 
1>   ] 
1>   c:\program files\microsoft visual studio 10.0\vc\include\xxcallpmf(9) : see reference to function template instantiation '_Ret std::tr1::_Pmf_caller2<_Ret,_Arg0>::_Apply_pmf<const _Ty,_Arg,boost::arg<I>>(_Pmf,_Farg0 &,_Farg1 &)' being compiled 
1>   with 
1>   [ 
1>    _Ret=_Rx, 
1>    _Arg0=BarLib::Bar, 
1>    _Ty=void (__thiscall BarLib::Bar::* const)(std::string), 
1>    _Arg=BarLib::Bar *, 
1>    I=1, 
1>    _Pmf=void (__thiscall BarLib::Bar::* const)(std::string), 
1>    _Farg0=BarLib::Bar *, 
1>    _Farg1=boost::arg<1> 
1>   ] 
1>   c:\program files\microsoft visual studio 10.0\vc\include\xxbind1(292) : see reference to function template instantiation '_Ret std::tr1::_Callable_pmf<_Ty,_Memty,_Indirect>::_ApplyX<_Ret,_Arg&,boost::arg<I>&>(_Arg0,_Arg1) const' being compiled 
1>   with 
1>   [ 
1>    _Ret=_Rx, 
1>    _Ty=void (__thiscall BarLib::Bar::* const)(std::string), 
1>    _Memty=BarLib::Bar, 
1>    _Indirect=false, 
1>    _Arg=BarLib::Bar *, 
1>    I=1, 
1>    _Arg0=BarLib::Bar *&, 
1>    _Arg1=boost::arg<1> & 
1>   ] 
1>   c:\program files\microsoft visual studio 10.0\vc\include\xxbind0(31) : see reference to function template instantiation '_Ret std::tr1::_Bind2<_Callable,_Arg0,_Arg1>::_ApplyX<_Rx,std::basic_string<_Elem,_Traits,_Ax>&,std::tr1::_Nil&,std::tr1::_Nil&,std::tr1::_Nil&,std::tr1::_Nil&,std::tr1::_Nil&,std::tr1::_Nil&,std::tr1::_Nil&,std::tr1::_Nil&,std::tr1::_Nil&>(_Barg0,_Barg1,_Barg2,_Barg3,_Barg4,_Barg5,_Barg6,_Barg7,_Barg8,_Barg9)' being compiled 
1>   with 
1>   [ 
1>    _Ret=_Rx, 
1>    _Callable=std::tr1::_Callable_pmf<void (__thiscall BarLib::Bar::* const)(std::string),BarLib::Bar,false>, 
1>    _Arg0=BarLib::Bar *, 
1>    _Arg1=boost::arg<1>, 
1>    _Elem=char, 
1>    _Traits=std::char_traits<char>, 
1>    _Ax=std::allocator<char>, 
1>    _Barg0=std::string &, 
1>    _Barg1=std::tr1::_Nil &, 
1>    _Barg2=std::tr1::_Nil &, 
1>    _Barg3=std::tr1::_Nil &, 
1>    _Barg4=std::tr1::_Nil &, 
1>    _Barg5=std::tr1::_Nil &, 
1>    _Barg6=std::tr1::_Nil &, 
1>    _Barg7=std::tr1::_Nil &, 
1>    _Barg8=std::tr1::_Nil &, 
1>    _Barg9=std::tr1::_Nil & 
1>   ] 
1>   c:\program files\microsoft visual studio 10.0\vc\include\xxcallobj(13) : see reference to function template instantiation 'void std::tr1::_Bind_base<_Ret,_BindN>::operator()<_Arg0&>(_Carg0)' being compiled 
1>   with 
1>   [ 
1>    _Ret=void, 
1>    _BindN=std::tr1::_Bind2<std::tr1::_Callable_pmf<void (__thiscall BarLib::Bar::* const)(std::string),BarLib::Bar,false>,BarLib::Bar *,boost::arg<1>>, 
1>    _Arg0=std::string, 
1>    _Carg0=std::string & 
1>   ] 
1>   c:\program files\microsoft visual studio 10.0\vc\include\xxfunction(65) : see reference to function template instantiation '_Ret std::tr1::_Callable_obj<_Ty>::_ApplyX<_Rx,_Arg0&>(std::basic_string<_Elem,_Traits,_Ax>)' being compiled 
1>   with 
1>   [ 
1>    _Ret=void, 
1>    _Ty=std::tr1::_Bind<void,void,std::tr1::_Bind2<std::tr1::_Callable_pmf<void (__thiscall BarLib::Bar::* const)(std::string),BarLib::Bar,false>,BarLib::Bar *,boost::arg<1>>>, 
1>    _Rx=void, 
1>    _Arg0=std::string, 
1>    _Elem=char, 
1>    _Traits=std::char_traits<char>, 
1>    _Ax=std::allocator<char> 
1>   ] 
1>   c:\program files\microsoft visual studio 10.0\vc\include\xxfunction(64) : while compiling class template member function 'void std::tr1::_Impl_no_alloc1<_Callable,_Rx,_Arg0>::_Do_call(_Arg0)' 
1>   with 
1>   [ 
1>    _Callable=_MyWrapper, 
1>    _Rx=void, 
1>    _Arg0=std::string 
1>   ] 
1>   c:\program files\microsoft visual studio 10.0\vc\include\xxfunction(386) : see reference to class template instantiation 'std::tr1::_Impl_no_alloc1<_Callable,_Rx,_Arg0>' being compiled 
1>   with 
1>   [ 
1>    _Callable=_MyWrapper, 
1>    _Rx=void, 
1>    _Arg0=std::string 
1>   ] 
1>   c:\program files\microsoft visual studio 10.0\vc\include\xxfunction(369) : see reference to function template instantiation 'void std::tr1::_Function_impl1<_Ret,_Arg0>::_Reset0o<_Myimpl,_Fty,std::allocator<_Ty>>(_Fty,_Alloc)' being compiled 
1>   with 
1>   [ 
1>    _Ret=void, 
1>    _Arg0=std::string, 
1>    _Fty=std::tr1::_Bind<void,void,std::tr1::_Bind2<std::tr1::_Callable_pmf<void (__thiscall BarLib::Bar::* const)(std::string),BarLib::Bar,false>,BarLib::Bar *,boost::arg<1>>>, 
1>    _Ty=std::tr1::_Function_impl1<void,std::string>, 
1>    _Alloc=std::allocator<std::tr1::_Function_impl1<void,std::string>> 
1>   ] 
1>   c:\program files\microsoft visual studio 10.0\vc\include\functional(113) : see reference to function template instantiation 'void std::tr1::_Function_impl1<_Ret,_Arg0>::_Reset<_Fx>(_Fty)' being compiled 
1>   with 
1>   [ 
1>    _Ret=void, 
1>    _Arg0=std::string, 
1>    _Fx=std::tr1::_Bind<void,void,std::tr1::_Bind2<std::tr1::_Callable_pmf<void (__thiscall BarLib::Bar::* const)(std::string),BarLib::Bar,false>,BarLib::Bar *,boost::arg<1>>>, 
1>    _Fty=std::tr1::_Bind<void,void,std::tr1::_Bind2<std::tr1::_Callable_pmf<void (__thiscall BarLib::Bar::* const)(std::string),BarLib::Bar,false>,BarLib::Bar *,boost::arg<1>>> 
1>   ] 
1>   d:\svn.dra.workingcopy\acquisition\native\xraygenerator\gemammogenerator.cpp(101) : see reference to function template instantiation 'std::tr1::function<_Fty>::function<std::tr1::_Bind<_Result_type,_Ret,_BindN>>(_Fx)' being compiled 
1>   with 
1>   [ 
1>    _Fty=void (std::string), 
1>    _Result_type=void, 
1>    _Ret=void, 
1>    _BindN=std::tr1::_Bind2<std::tr1::_Callable_pmf<void (__thiscall BarLib::Bar::* const)(std::string),BarLib::Bar,false>,BarLib::Bar *,boost::arg<1>>, 
1>    _Fx=std::tr1::_Bind<void,void,std::tr1::_Bind2<std::tr1::_Callable_pmf<void (__thiscall BarLib::Bar::* const)(std::string),BarLib::Bar,false>,BarLib::Bar *,boost::arg<1>>> 
1>   ] 
1> 
1>Build FAILED. 

¿Qué está pasando? ¿Tal vez debería eliminar las referencias a los encabezados de Boost?

Respuesta

16

es probable que necesite para incluir <functional> y explícitamente utilizar el espacio de nombres de marcadores de posición para la Edición _1

using namespace std::placeholders; 

: Como se ha señalado en los comentarios, también necesitaría para eliminar las cabeceras de impulso que traen los marcadores de posición en el espacio de nombres global.

+2

esto probablemente lo hará, pero el OP también tendrá que eliminar el impulso incluye else else _1 se define dos veces; o, use std :: placeholders :: _ 1 explícitamente – stijn

+0

@stijn ¡buen punto, gracias! Añadiré eso a mi respuesta. – juanchopanza

Cuestiones relacionadas