函数从bind不编译

函数从bind不编译

本文介绍了VC2013:函数从bind不编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 以下是一个简短示例: class A {}; class S {}; class B { public: typedef std :: function< bool(A& retVal)> property_getter_t; typedef std :: function< bool(B * / * this * /,const std :: shared_ptr& amp; amp; retVal)> SettingsPropGetter; void DefineSettingsProperty(const std :: wstring& name,const SettingsPropGetter& getter) { auto fn_g = std :: bind(getter,this,std :: placeholders: :_1,std :: placeholders :: _ 2); auto fn_gg = std :: bind(& B :: GetterHandler,this,fn_g,std :: placeholders :: _ 1); property_getter_t x = fn_gg; // PROBLEM IS HERE } bool GetterHandler(const std :: function< bool(const std :: shared_ptr< S&&)>& getter,A& ; a) { std :: shared_ptr< S> s; return getter(s,a); } }; 该代码在VC2010下编译得很好。 在VC2013下,我会收到一大堆错误。 出了什么问题? 这里有错误: 1> c:\program files(x86)\microsoft visual studio 12.0 \vc\include\tuple(540):error C2504:'std :: tuple_element< 0,std :: tuple& ':base class undefined 1> c:\program files(x86)\microsoft visual studio 12.0 \vc\include\functional(900):参见类模板实例化'std :: tuple_element< 1,_Ftuple& b 1> with 1> [ 1> _Ftuple = std :: tuple< A&> 1> ] 1> c:\program files(x86)\microsoft visual studio 12.0 \vc\include\functional(946):参见类模板实例化的参考std :: _ Fixarg_ret_base< _Placeholder,_Funx,std :: _ Ph& ;,_ Ftuple>'被编译 1> with 1> [ 1> _Funx = std :: function< bool(B *,const std :: shared_ptr&,A&)> 1> ,_Ftuple = std :: tuple< A&> 1> ] 1> c:\program files(x86)\microsoft visual studio 12.0 \vc\include\functional(975):参见类模板实例化的参考'std :: _ Fixarg_ret< _Funx,std :: _ Ph& &,_ Ftuple>'正在编译 1> with 1> [ 1> _Funx = std :: function< bool(B *,const std :: shared_ptr&,A&)> 1> ,_Ftuple = std :: tuple< A&> 1> ] 1> c:\program files(x86)\microsoft visual studio 12.0 \vc\include\xrefwrap(58):参见类模板实例化的参考std :: _ Do_call_ret< false,_Ret,std :: function< bool (B *,const std :: shared_ptr&,A&)>,std :: tuple< B *,std :: _ ph 1,std :: _ ph 2& :tuple< A&>,std :: _Arg_idx< 0,1,2>'被编译 1> with 1> [ 1> _Ret = void 1> ] 1> c:\program files(x86)\microsoft visual studio 12.0 \vc\include\xrefwrap(118):请参阅类模板实例化的参考'std :: _ Result_of< _Fty,A&> 1> with 1> [ 1> _Fty = std :: _Bind< false,void,const B :: SettingsPropGetter&,B * const,std :: _ &,std :: _ Ph 2 &> 1> ] 1> c:\program files(x86)\microsoft visual studio 12.0 \vc\include\functional(914):参见类模板实例化的参考'std :: result_of< _Bind_t(A&)>'编译 1> with 1> [ 1> _Bind_t = std :: _Bind< false,void,const B :: SettingsPropGetter&,B * const,std :: _ &,std :: _ Ph 2 &> 1> ] 1> c:\program files(x86)\microsoft visual studio 12.0 \vc\include\functional(924):参见类模板实例化'std :: _ Call_ret< _Barg,std :: tuple< A& >,std :: _Arg_idx 0>'被编译 1> with 1> [ 1> _Barg = std :: _Bind< false,void,const B :: SettingsPropGetter&,B * const,std :: _ &,std :: _ Ph 2 &> 1> ] 1> c:\program files(x86)\microsoft visual studio 12.0 \vc\include\functional(946):参见类模板实例化的引用'std :: _ Fixarg_ret_base< _Bind_expression,_Funx,std :: _Bind< false ,void,const B :: SettingsPropGetter&,B * const,std :: _ ph 1, &,std :: _ Ph 2 &>,_ Ftuple>'正在编译 1> with 1> [ 1> _Funx = std :: _ Pmf_wrap< bool(__thiscall B :: *)(const std :: function< bool(const std :: shared_ptr&,A&)&,A& ,B,const std :: function< bool(const std :: shared_ptr&,A&)> &,A&> & 1> ,_Ftuple = std :: tuple< A&> 1> ] 1> c:\program files(x86)\microsoft visual studio 12.0 \vc\include\functional(1148):参见类模板实例化的参考std :: _ Fixarg_ret< std :: _ Pmf_wrap< bool(__thiscall B: :*)(const std :: function< bool(const std :: shared_ptr&,A&)&,&,A&),bool,B,const std :: function< bool std :: shared_ptr< S>&,A&)> &,A&> &,_ Ty,std :: tuple< A&>>'正在编译 1> with 1> [ 1> _Ty = std :: _Bind< false,void,const B :: SettingsPropGetter&,B * const,std :: _ &,std :: _ Ph 2 &> 1> ] 1> c:\program files(x86)\microsoft visual studio 12.0 \vc\include\functional(1137):参见函数模板实例化bool std :: _Bind< true,bool,std :: _ Pmf_wrap< bool(__thiscall B :: *)(const std :: function< bool(const std :: shared_ptr< S&,A&)&,A&),bool,B,const std :: function< bool(const std :: shared_ptr< S&,A&)> &,A&>,B * const,std :: _Bind< false,void,const B :: SettingsPropGetter&,B * const,std :: _ &,std :: _ Ph 2 &> &,std :: _ ph 1。 &> :: _ Do_call< A,0,1,2>(std :: tuple< A&>,std :: _Arg_idx< 0,1,2>)' 1& c:\program files(x86)\microsoft visual studio 12.0 \vc\include\functional(1137):参见函数模板实例化bool std :: _Bind< true,bool,std :: _ Pmf_wrap< bool(__thiscall B :: *)(const std :: function< bool(const std :: shared_ptr< S&,A&)&,A&),bool,B,const std :: function< bool(const std :: shared_ptr< S&,A&)> &,A&>,B * const,std :: _Bind< false,void,const B :: SettingsPropGetter&,B * const,std :: _ &,std :: _ Ph 2 &> &,std :: _ ph 1。 &> :: _ Do_call< A,0,1,2>(std :: tuple< A&>,std :: _Arg_idx< 0,1,2>)' 1& c:\program files(x86)\microsoft visual studio 12.0 \vc\include\xrefwrap(283):参见函数模板实例化的参考'bool std :: _Bind< true,bool,std :: _ Pmf_wrap< bool(__thiscall B :: *)(const std :: function< bool(const std :: shared_ptr< S&,A&)&,A&),bool,B,const std :: function< bool(const std :: shared_ptr< S&,A&)> &,A&>,B * const,std :: _Bind< false,void,const B :: SettingsPropGetter&,B * const,std :: _ &,std :: _ Ph 2 &> &,std :: _ ph 1。 &> :: operator()< A&>(A&)'被编译 1> c:\program files(x86)\microsoft visual studio 12.0 \vc\include\xrefwrap(283):参见函数模板实例化的参考'bool std :: _Bind< true,bool,std :: _ Pmf_wrap< bool(__thiscall B :: *)(const std :: function< bool(const std :: shared_ptr< S&,A&)&,A&),bool,B,const std :: function< bool(const std :: shared_ptr< S&,A&)> &,A&>,B * const,std :: _Bind< false,void,const B :: SettingsPropGetter&,B * const,std :: _ &,std :: _ Ph 2 &> &,std :: _ ph 1。 &> :: operator()< A&>(A&)'被编译 1> c:\program files(x86)\microsoft visual studio 12.0 \vc\include\functional(228):参见函数模板实例化_Ret std :: _ Callable_obj< std :: _Bind< true,_Ret, std :: _Pmf_wrap< bool(__thiscall B :: *)(const std :: function< bool(const std :: shared_ptr&,A&)&,A&),bool,B ,const std :: function< bool(const std :: shared_ptr&,A&)> &,A&>,B * const,std :: _Bind< false,void,const B :: SettingsPropGetter&,B * const,std :: _ &,std :: _ Ph 2 &> &,std :: _ ph 1。 &>,false> :: _ ApplyX< _Rx,A&>(A&)'被编译 1& with 1> [ 1> _Ret = bool 1> ,_Rx = bool 1> ] 1> c:\program files(x86)\microsoft visual studio 12.0 \vc\include\functional(228):参见函数模板实例化_Ret std :: _ Callable_obj< std :: _Bind< true,_Ret, std :: _Pmf_wrap< bool(__thiscall B :: *)(const std :: function< bool(const std :: shared_ptr&,A&)&,A&),bool,B ,const std :: function< bool(const std :: shared_ptr&,A&)> &,A&>,B * const,std :: _Bind< false,void,const B :: SettingsPropGetter&,B * const,std :: _ &,std :: _ Ph 2 &> &,std :: _ ph 1。 &>,false> :: _ ApplyX< _Rx,A&>(A&)'被编译 1& with 1> [ 1> _Ret = bool 1> ,_Rx = bool 1> ] 1> c:\program files(x86)\microsoft visual studio 12.0 \vc\include\functional(226):在编译类模板成员函数'bool std :: _ Func_impl< _MyWrapper,_Alloc,_Ret,A& > :: _ Do_call(A&)' 1> with 1> [ 1> _Alloc = std :: allocator< std :: _ Func_class< bool,A&>> 1> ,_Ret = bool 1> ] 1> c:\program files(x86)\microsoft visual studio 12.0 \vc\include\functional(495):参见类模板实例化的参考'std :: _ Func_impl< _MyWrapper,_Alloc,_Ret,A& ;'正在编译 1> with 1> [ 1> _Alloc = std :: allocator< std :: _ Func_class< bool,A&>> 1> ,_Ret = bool 1> ] 1> c:\program files(x86)\microsoft visual studio 12.0 \vc\include\functional(396):参见函数模板实例化的参考void std :: _ Func_class< _Ret,A& _Do_alloc< _Myimpl,std :: _Bind< true,_Ret,std :: _Pmf_wrap< bool(__thiscall B :: *)(const std :: function< bool(const std :: shared_ptr&,A& &,A&),bool,B,const std :: function< bool(const std :: shared_ptr&,A& &,A&>,B * const,std :: _Bind< false,void,const B :: SettingsPropGetter&,B * const,std :: _ &,std :: _ Ph 2 &> &,std :: _ ph 1。 &>&,_ Alloc>(_ Fty,_Alloc)' 1> with 1> [ 1> _Ret = bool 1> ,_Alloc = std :: allocator< std :: _ Func_class< bool,A&>> 1> ,_Fty = std :: _Bind< true,bool,std :: _ Pmf_wrap< bool(__thiscall B :: *)(const std :: function< bool(const std :: shared_ptr&,A& ;&,A&),bool,B,const std :: function< bool(const std :: shared_ptr&,A& &,A&>,B * const,std :: _Bind< false,void,const B :: SettingsPropGetter&,B * const,std :: _ &,std :: _ Ph 2 &> &,std :: _ ph 1。 &> & 1> ] 1> c:\program files(x86)\microsoft visual studio 12.0 \vc\include\functional(396):参见函数模板实例化的参考void std :: _ Func_class< _Ret,A&> _Do_alloc< _Myimpl,std :: _Bind< true,_Ret,std :: _Pmf_wrap< bool(__thiscall B :: *)(const std :: function< bool(const std :: shared_ptr&,A& &,A&),bool,B,const std :: function< bool(const std :: shared_ptr&,A& &,A&>,B * const,std :: _Bind< false,void,const B :: SettingsPropGetter&,B * const,std :: _ &,std :: _ Ph 2 &> &,std :: _ ph 1。 &>&,_ Alloc>(_ Fty,_Alloc)' 1> with 1> [ 1> _Ret = bool 1> ,_Alloc = std :: allocator< std :: _ Func_class< bool,A&>> 1> ,_Fty = std :: _Bind< true,bool,std :: _ Pmf_wrap< bool(__thiscall B :: *)(const std :: function< bool(const std :: shared_ptr&,A& ;&,A&),bool,B,const std :: function< bool(const std :: shared_ptr&,A& &,A&>,B * const,std :: _Bind< false,void,const B :: SettingsPropGetter&,B * const,std :: _ &,std :: _ Ph 2 &> &,std :: _ ph 1。 &> & 1> ] 1> c:\program files(x86)\microsoft visual studio 12.0 \vc\include\functional(385):参见函数模板实例化的参考void std :: _ Func_class< _Ret,A&> _Reset_alloc< std :: _Bind< true,_Ret,std :: _Pmf_wrap< bool(__thiscall B :: *)(const std :: function< bool(const std :: shared_ptr&,A& &,A&),bool,B,const std :: function< bool(const std :: shared_ptr&,A& &,A&>,B * const,std :: _Bind< false,void,const B :: SettingsPropGetter&,B * const,std :: _ &,std :: _ Ph 2 &> &,std :: _ ph 1。 &>&>&,std :: allocator< std :: _ Func_class< _Ret,A&>>>(_ Fty,_Alloc)' 1& with 1> [ 1> _Ret = bool 1> ,_Fty = std :: _Bind< true,bool,std :: _ Pmf_wrap< bool(__thiscall B :: *)(const std :: function< bool(const std :: shared_ptr&,A& ;&,A&),bool,B,const std :: function< bool(const std :: shared_ptr&,A& &,A&>,B * const,std :: _Bind< false,void,const B :: SettingsPropGetter&,B * const,std :: _ &,std :: _ Ph 2 &> &,std :: _ ph 1。 &> & 1> ,_Alloc = std :: allocator< std :: _ Func_class< bool,A&>> 1> ] 1> c:\program files(x86)\microsoft visual studio 12.0 \vc\include\functional(385):参见函数模板实例化的参考void std :: _ Func_class< _Ret,A&> _Reset_alloc< std :: _Bind< true,_Ret,std :: _Pmf_wrap< bool(__thiscall B :: *)(const std :: function< bool(const std :: shared_ptr&,A& &,A&),bool,B,const std :: function< bool(const std :: shared_ptr&,A& &,A&>,B * const,std :: _Bind< false,void,const B :: SettingsPropGetter&,B * const,std :: _ &,std :: _ Ph 2 &> &,std :: _ ph 1。 &>&>&,std :: allocator< std :: _ Func_class< _Ret,A&>>>(_ Fty,_Alloc)' 1> with 1> [ 1> _Ret = bool 1> ,_Fty = std :: _Bind< true,bool,std :: _ Pmf_wrap< bool(__thiscall B :: *)(const std :: function< bool(const std :: shared_ptr&,A& ;&,A&),bool,B,const std :: function< bool(const std :: shared_ptr&,A& &,A&>,B * const,std :: _Bind< false,void,const B :: SettingsPropGetter&,B * const,std :: _ &,std :: _ Ph 2 &> &,std :: _ ph 1。 &> & 1> ,_Alloc = std :: allocator< std :: _ Func_class< bool,A&>> 1> ] 1> c:\program files(x86)\microsoft visual studio 12.0 \vc\include\functional(671):参见函数模板实例化的参考void std :: _ Func_class< _Ret,A& _Reset< std :: _Bind< true,_Ret,std :: _Pmf_wrap< bool(__thiscall B :: *)(const std :: function< bool(const std :: shared_ptr&,A& &,A&),bool,B,const std :: function< bool(const std :: shared_ptr&,A& &,A&>,B * const,std :: _Bind< false,void,const B :: SettingsPropGetter&,B * const,std :: _ &,std :: _ Ph 2 &> &,std :: _ ph 1。 &>&>(_ Fty)' 1> with 1> [ 1> _Ret = bool 1> ,_Fty = std :: _Bind< true,bool,std :: _ Pmf_wrap< bool(__thiscall B :: *)(const std :: function< bool(const std :: shared_ptr&,A& ;&,A&),bool,B,const std :: function< bool(const std :: shared_ptr&,A& &,A&>,B * const,std :: _Bind< false,void,const B :: SettingsPropGetter&,B * const,std :: _ &,std :: _ Ph 2 &> &,std :: _ ph 1。 &> & 1> ] 1> c:\program files(x86)\microsoft visual studio 12.0 \vc\include\functional(671):参见函数模板实例化的参考void std :: _ Func_class< _Ret,A& _Reset< std :: _Bind< true,_Ret,std :: _ Pmf_wrap< bool(__thiscall B :: *)(const std :: function< bool(const std :: shared_ptr&,A& &,A&),bool,B,const std :: function< bool(const std :: shared_ptr&,A& &,A&>,B * const,std :: _Bind< false,void,const B :: SettingsPropGetter&,B * const,std :: _ &,std :: _ Ph 2 &> &,std :: _ ph 1。 &>&>(_ Fty)' 1> with 1> [ 1> _Ret = bool 1> ,_Fty = std :: _Bind< true,bool,std :: _ Pmf_wrap< bool(__thiscall B :: *)(const std :: function< bool(const std :: shared_ptr&,A& ;&,A&),bool,B,const std :: function< bool(const std :: shared_ptr&,A& &,A&>,B * const,std :: _Bind< false,void,const B :: SettingsPropGetter&,B * const,std :: _ &,std :: _ Ph 2 &> &,std :: _ ph 1。 &> & 1> ] 1> c:\work\source\test.cpp(29):参见对函数模板实例化的引用'std :: function 1> with 1> [ 1> _Fx = std :: _Bind< true,bool,std :: _ Pmf_wrap< bool(__thiscall B :: *)(const std :: function< bool(const std :: shared_ptr&,A& &,A&),bool,B,const std :: function< bool(const std :: shared_ptr&,A& &,A&>,B * const,std :: _Bind< false,void,const B :: SettingsPropGetter&,B * const,std :: _ &,std :: _ Ph 2 &> &,std :: _ ph 1。 &> & 1> ] 1> c:\work\source\test.cpp(29):参见对函数模板实例化的引用'std :: function 1> with 1> [ 1> _Fx = std :: _Bind< true,bool,std :: _ Pmf_wrap< bool(__thiscall B :: *)(const std :: function< bool(const std :: shared_ptr&,A& &,A&),bool,B,const std :: function< bool(const std :: shared_ptr&,A& &,A&>,B * const,std :: _Bind< false,void,const B :: SettingsPropGetter&,B * const,std :: _ &,std :: _ Ph 2 &> &,std :: _ ph 1。 &> & 1> ] 1> c:\program files(x86)\microsoft visual studio 12.0 \vc\include\functional(900):error C2039:'type':不是'std: :tuple_element< 1,_Ftuple>' 1> with 1> [ 1> _Ftuple = std :: tuple< A&> 1> ] 1> c:\program files(x86)\microsoft visual studio 12.0 \vc\include\functional(900):error C2146:syntax error:missing','before identifier'type' 1> c:\program files(x86)\microsoft visual studio 12.0 \vc\include\functional(900):error C2065:'type':undeclared identifier 1> c :\program files(x86)\microsoft visual studio 12.0 \vc\include\functional(900):error C2977:'std :: add_reference':模板参数太多 1> c:\program files(x86)\microsoft visual studio 12.0 \vc\include\type_traits(180):参见std :: add_reference的声明 1> c:\program files x86)\microsoft visual studio 12.0 \vc\include\functional(900):error C2955:'std :: add_reference':使用类模板需要模板参数列表 1> c:\program files(x86)\microsoft visual studio 12.0 \vc\include\type_traits(180):参见std :: add_reference的声明 pre> c:\work\source\test.cpp(29) - 是我的源文件(PROBLEM IS HERE注释)。 / p> 解决方案我通常会引用标准,但是这里的标准特别密集,所以我只是解释一下发生了什么。 p> std :: bind 在传递要绑定的参数时执行某些特殊操作,如果该参数是返回的函数对象先前调用 std :: bind 。假设你这样做: auto f = std :: bind(foo,std :: placeholders :: _ 1); auto g = std :: bind(bar,f,std :: placeholders :: _ 1); 然后调用 g(a)相当于 bar(foo(a),a) 而不是 bar(f,a) 演示。 也就是说,如果将 bind 返回的内容传递给 bind 作为绑定的参数,最终传递给绑定的函数的是调用该绑定表达式的结果。这是一种组合。 但是,在你的代码中,你实际上不希望组合发生。 (这个组合是什么导致g ++发出320+行错误,当我试图调用 fn_gg 在 A 。Clang with libc ++只打印10行,幸运的是。)你想要 fn_g 就像一个普通的参数。所以你可以将它包装在 std :: function : std :: function< bool(const std :: shared_ptr< S& amp; A&)> fn_g = std :: bind(getter,this,std :: placeholders :: _ 1,std :: placeholders :: _ 2); Here is a short sample:class A {};class S {};class B{public: typedef std::function <bool (A& retVal)> property_getter_t; typedef std::function<bool (B* /*this*/, const std::shared_ptr<S>&, A& retVal)> SettingsPropGetter; void DefineSettingsProperty(const std::wstring& name, const SettingsPropGetter& getter) { auto fn_g = std::bind(getter, this, std::placeholders::_1, std::placeholders::_2); auto fn_gg = std::bind(&B::GetterHandler, this, fn_g, std::placeholders::_1); property_getter_t x = fn_gg; // PROBLEM IS HERE } bool GetterHandler(const std::function<bool (const std::shared_ptr<S>&, A&)>& getter, A& a) { std::shared_ptr <S> s; return getter (s, a); }};The code compiles fine under VC2010. Under VC2013 I keep getting a huge pack of errors.What's wrong? Can this be fixed somehow?Here are the errors:1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\tuple(540): error C2504: 'std::tuple_element<0,std::tuple<>>' : base class undefined1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(900) : see reference to class template instantiation 'std::tuple_element<1,_Ftuple>' being compiled1> with1> [1> _Ftuple=std::tuple<A &>1> ]1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(946) : see reference to class template instantiation 'std::_Fixarg_ret_base<_Placeholder,_Funx,std::_Ph<2>,_Ftuple>' being compiled1> with1> [1> _Funx=std::function<bool (B *,const std::shared_ptr<S> &,A &)>1> , _Ftuple=std::tuple<A &>1> ]1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(975) : see reference to class template instantiation 'std::_Fixarg_ret<_Funx,std::_Ph<2> &,_Ftuple>' being compiled1> with1> [1> _Funx=std::function<bool (B *,const std::shared_ptr<S> &,A &)>1> , _Ftuple=std::tuple<A &>1> ]1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\xrefwrap(58) : see reference to class template instantiation 'std::_Do_call_ret<false,_Ret,std::function<bool (B *,const std::shared_ptr<S> &,A &)>,std::tuple<B *,std::_Ph<1>,std::_Ph<2>>,std::tuple<A &>,std::_Arg_idx<0,1,2>>' being compiled1> with1> [1> _Ret=void1> ]1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\xrefwrap(118) : see reference to class template instantiation 'std::_Result_of<_Fty,A &>' being compiled1> with1> [1> _Fty=std::_Bind<false,void,const B::SettingsPropGetter &,B *const ,std::_Ph<1> &,std::_Ph<2> &>1> ]1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(914) : see reference to class template instantiation 'std::result_of<_Bind_t (A &)>' being compiled1> with1> [1> _Bind_t=std::_Bind<false,void,const B::SettingsPropGetter &,B *const ,std::_Ph<1> &,std::_Ph<2> &>1> ]1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(924) : see reference to class template instantiation 'std::_Call_ret<_Barg,std::tuple<A &>,std::_Arg_idx<0>>' being compiled1> with1> [1> _Barg=std::_Bind<false,void,const B::SettingsPropGetter &,B *const ,std::_Ph<1> &,std::_Ph<2> &>1> ]1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(946) : see reference to class template instantiation 'std::_Fixarg_ret_base<_Bind_expression,_Funx,std::_Bind<false,void,const B::SettingsPropGetter &,B *const ,std::_Ph<1> &,std::_Ph<2> &>,_Ftuple>' being compiled1> with1> [1> _Funx=std::_Pmf_wrap<bool (__thiscall B::* )(const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &),bool,B,const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &> &1> , _Ftuple=std::tuple<A &>1> ]1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(1148) : see reference to class template instantiation 'std::_Fixarg_ret<std::_Pmf_wrap<bool (__thiscall B::* )(const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &),bool,B,const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &> &,_Ty,std::tuple<A &>>' being compiled1> with1> [1> _Ty=std::_Bind<false,void,const B::SettingsPropGetter &,B *const ,std::_Ph<1> &,std::_Ph<2> &>1> ]1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(1137) : see reference to function template instantiation 'bool std::_Bind<true,bool,std::_Pmf_wrap<bool (__thiscall B::* )(const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &),bool,B,const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &>,B *const ,std::_Bind<false,void,const B::SettingsPropGetter &,B *const ,std::_Ph<1> &,std::_Ph<2> &> &,std::_Ph<1> &>::_Do_call<A,0,1,2>(std::tuple<A &>,std::_Arg_idx<0,1,2>)' being compiled1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(1137) : see reference to function template instantiation 'bool std::_Bind<true,bool,std::_Pmf_wrap<bool (__thiscall B::* )(const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &),bool,B,const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &>,B *const ,std::_Bind<false,void,const B::SettingsPropGetter &,B *const ,std::_Ph<1> &,std::_Ph<2> &> &,std::_Ph<1> &>::_Do_call<A,0,1,2>(std::tuple<A &>,std::_Arg_idx<0,1,2>)' being compiled1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\xrefwrap(283) : see reference to function template instantiation 'bool std::_Bind<true,bool,std::_Pmf_wrap<bool (__thiscall B::* )(const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &),bool,B,const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &>,B *const ,std::_Bind<false,void,const B::SettingsPropGetter &,B *const ,std::_Ph<1> &,std::_Ph<2> &> &,std::_Ph<1> &>::operator ()<A&>(A &)' being compiled1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\xrefwrap(283) : see reference to function template instantiation 'bool std::_Bind<true,bool,std::_Pmf_wrap<bool (__thiscall B::* )(const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &),bool,B,const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &>,B *const ,std::_Bind<false,void,const B::SettingsPropGetter &,B *const ,std::_Ph<1> &,std::_Ph<2> &> &,std::_Ph<1> &>::operator ()<A&>(A &)' being compiled1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(228) : see reference to function template instantiation '_Ret std::_Callable_obj<std::_Bind<true,_Ret,std::_Pmf_wrap<bool (__thiscall B::* )(const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &),bool,B,const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &>,B *const ,std::_Bind<false,void,const B::SettingsPropGetter &,B *const ,std::_Ph<1> &,std::_Ph<2> &> &,std::_Ph<1> &>,false>::_ApplyX<_Rx,A&>(A &)' being compiled1> with1> [1> _Ret=bool1> , _Rx=bool1> ]1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(228) : see reference to function template instantiation '_Ret std::_Callable_obj<std::_Bind<true,_Ret,std::_Pmf_wrap<bool (__thiscall B::* )(const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &),bool,B,const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &>,B *const ,std::_Bind<false,void,const B::SettingsPropGetter &,B *const ,std::_Ph<1> &,std::_Ph<2> &> &,std::_Ph<1> &>,false>::_ApplyX<_Rx,A&>(A &)' being compiled1> with1> [1> _Ret=bool1> , _Rx=bool1> ]1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(226) : while compiling class template member function 'bool std::_Func_impl<_MyWrapper,_Alloc,_Ret,A &>::_Do_call(A &)'1> with1> [1> _Alloc=std::allocator<std::_Func_class<bool,A &>>1> , _Ret=bool1> ]1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(495) : see reference to class template instantiation 'std::_Func_impl<_MyWrapper,_Alloc,_Ret,A &>' being compiled1> with1> [1> _Alloc=std::allocator<std::_Func_class<bool,A &>>1> , _Ret=bool1> ]1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(396) : see reference to function template instantiation 'void std::_Func_class<_Ret,A &>::_Do_alloc<_Myimpl,std::_Bind<true,_Ret,std::_Pmf_wrap<bool (__thiscall B::* )(const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &),bool,B,const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &>,B *const ,std::_Bind<false,void,const B::SettingsPropGetter &,B *const ,std::_Ph<1> &,std::_Ph<2> &> &,std::_Ph<1> &>&,_Alloc>(_Fty,_Alloc)' being compiled1> with1> [1> _Ret=bool1> , _Alloc=std::allocator<std::_Func_class<bool,A &>>1> , _Fty=std::_Bind<true,bool,std::_Pmf_wrap<bool (__thiscall B::* )(const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &),bool,B,const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &>,B *const ,std::_Bind<false,void,const B::SettingsPropGetter &,B *const ,std::_Ph<1> &,std::_Ph<2> &> &,std::_Ph<1> &> &1> ]1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(396) : see reference to function template instantiation 'void std::_Func_class<_Ret,A &>::_Do_alloc<_Myimpl,std::_Bind<true,_Ret,std::_Pmf_wrap<bool (__thiscall B::* )(const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &),bool,B,const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &>,B *const ,std::_Bind<false,void,const B::SettingsPropGetter &,B *const ,std::_Ph<1> &,std::_Ph<2> &> &,std::_Ph<1> &>&,_Alloc>(_Fty,_Alloc)' being compiled1> with1> [1> _Ret=bool1> , _Alloc=std::allocator<std::_Func_class<bool,A &>>1> , _Fty=std::_Bind<true,bool,std::_Pmf_wrap<bool (__thiscall B::* )(const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &),bool,B,const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &>,B *const ,std::_Bind<false,void,const B::SettingsPropGetter &,B *const ,std::_Ph<1> &,std::_Ph<2> &> &,std::_Ph<1> &> &1> ]1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(385) : see reference to function template instantiation 'void std::_Func_class<_Ret,A &>::_Reset_alloc<std::_Bind<true,_Ret,std::_Pmf_wrap<bool (__thiscall B::* )(const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &),bool,B,const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &>,B *const ,std::_Bind<false,void,const B::SettingsPropGetter &,B *const ,std::_Ph<1> &,std::_Ph<2> &> &,std::_Ph<1> &>&,std::allocator<std::_Func_class<_Ret,A &>>>(_Fty,_Alloc)' being compiled1> with1> [1> _Ret=bool1> , _Fty=std::_Bind<true,bool,std::_Pmf_wrap<bool (__thiscall B::* )(const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &),bool,B,const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &>,B *const ,std::_Bind<false,void,const B::SettingsPropGetter &,B *const ,std::_Ph<1> &,std::_Ph<2> &> &,std::_Ph<1> &> &1> , _Alloc=std::allocator<std::_Func_class<bool,A &>>1> ]1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(385) : see reference to function template instantiation 'void std::_Func_class<_Ret,A &>::_Reset_alloc<std::_Bind<true,_Ret,std::_Pmf_wrap<bool (__thiscall B::* )(const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &),bool,B,const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &>,B *const ,std::_Bind<false,void,const B::SettingsPropGetter &,B *const ,std::_Ph<1> &,std::_Ph<2> &> &,std::_Ph<1> &>&,std::allocator<std::_Func_class<_Ret,A &>>>(_Fty,_Alloc)' being compiled1> with1> [1> _Ret=bool1> , _Fty=std::_Bind<true,bool,std::_Pmf_wrap<bool (__thiscall B::* )(const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &),bool,B,const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &>,B *const ,std::_Bind<false,void,const B::SettingsPropGetter &,B *const ,std::_Ph<1> &,std::_Ph<2> &> &,std::_Ph<1> &> &1> , _Alloc=std::allocator<std::_Func_class<bool,A &>>1> ]1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(671) : see reference to function template instantiation 'void std::_Func_class<_Ret,A &>::_Reset<std::_Bind<true,_Ret,std::_Pmf_wrap<bool (__thiscall B::* )(const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &),bool,B,const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &>,B *const ,std::_Bind<false,void,const B::SettingsPropGetter &,B *const ,std::_Ph<1> &,std::_Ph<2> &> &,std::_Ph<1> &>&>(_Fty)' being compiled1> with1> [1> _Ret=bool1> , _Fty=std::_Bind<true,bool,std::_Pmf_wrap<bool (__thiscall B::* )(const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &),bool,B,const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &>,B *const ,std::_Bind<false,void,const B::SettingsPropGetter &,B *const ,std::_Ph<1> &,std::_Ph<2> &> &,std::_Ph<1> &> &1> ]1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(671) : see reference to function template instantiation 'void std::_Func_class<_Ret,A &>::_Reset<std::_Bind<true,_Ret,std::_Pmf_wrap<bool (__thiscall B::* )(const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &),bool,B,const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &>,B *const ,std::_Bind<false,void,const B::SettingsPropGetter &,B *const ,std::_Ph<1> &,std::_Ph<2> &> &,std::_Ph<1> &>&>(_Fty)' being compiled1> with1> [1> _Ret=bool1> , _Fty=std::_Bind<true,bool,std::_Pmf_wrap<bool (__thiscall B::* )(const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &),bool,B,const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &>,B *const ,std::_Bind<false,void,const B::SettingsPropGetter &,B *const ,std::_Ph<1> &,std::_Ph<2> &> &,std::_Ph<1> &> &1> ]1> c:\work\source\test.cpp(29) : see reference to function template instantiation 'std::function<bool (A &)>::function<std::_Bind<true,bool,std::_Pmf_wrap<bool (__thiscall B::* )(const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &),bool,B,const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &>,B *const ,std::_Bind<false,void,const B::SettingsPropGetter &,B *const ,std::_Ph<1> &,std::_Ph<2> &> &,std::_Ph<1> &>&>(_Fx)' being compiled1> with1> [1> _Fx=std::_Bind<true,bool,std::_Pmf_wrap<bool (__thiscall B::* )(const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &),bool,B,const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &>,B *const ,std::_Bind<false,void,const B::SettingsPropGetter &,B *const ,std::_Ph<1> &,std::_Ph<2> &> &,std::_Ph<1> &> &1> ]1> c:\work\source\test.cpp(29) : see reference to function template instantiation 'std::function<bool (A &)>::function<std::_Bind<true,bool,std::_Pmf_wrap<bool (__thiscall B::* )(const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &),bool,B,const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &>,B *const ,std::_Bind<false,void,const B::SettingsPropGetter &,B *const ,std::_Ph<1> &,std::_Ph<2> &> &,std::_Ph<1> &>&>(_Fx)' being compiled1> with1> [1> _Fx=std::_Bind<true,bool,std::_Pmf_wrap<bool (__thiscall B::* )(const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &),bool,B,const std::function<bool (const std::shared_ptr<S> &,A &)> &,A &>,B *const ,std::_Bind<false,void,const B::SettingsPropGetter &,B *const ,std::_Ph<1> &,std::_Ph<2> &> &,std::_Ph<1> &> &1> ]1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(900): error C2039: 'type' : is not a member of 'std::tuple_element<1,_Ftuple>'1> with1> [1> _Ftuple=std::tuple<A &>1> ]1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(900): error C2146: syntax error : missing ',' before identifier 'type'1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(900): error C2065: 'type' : undeclared identifier1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(900): error C2977: 'std::add_reference' : too many template arguments1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\type_traits(180) : see declaration of 'std::add_reference'1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(900): error C2955: 'std::add_reference' : use of class template requires template argument list1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\type_traits(180) : see declaration of 'std::add_reference'c:\work\source\test.cpp(29) - is my source file (where the "PROBLEM IS HERE" comment is). 解决方案 I would normally quote the standard, but the standardese here is particularly dense, so I'll just explain what's happening.std::bind does something special when you pass an argument to be bound if that argument is a function object returned by a previous call to std::bind. Suppose you do:auto f = std::bind(foo, std::placeholders::_1);auto g = std::bind(bar, f, std::placeholders::_1);Then invoking g(a) is roughly equivalent tobar(foo(a), a)rather thanbar(f, a)Demo.That is, if you pass something returned by bind to bind as an argument to be bound, what's going to end up being passed to the function you are binding is the result of invoking that bind expression. It's a sort of composition.However, in your code, you actually don't want the composition to take place. (This composition is what caused g++ to emit 320+ lines of errors when I tried to call your fn_gg on an A. Clang with libc++ printed only 10 lines, thankfully.) You want fn_g to be treated just like an ordinary argument. So you can wrap it in a std::function:std::function<bool (const std::shared_ptr<S>&, A&)> fn_g = std::bind(getter, this, std::placeholders::_1, std::placeholders::_2); 这篇关于VC2013:函数从bind不编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-30 08:40