首页 文章

使用tr1 :: function时编译错误

提问于
浏览
0

目的是在CDevVS890中调用m_callback_fn时执行CVS890Executor :: do_full_frame .

以下是有罪的代码:

"CDevVS890.h"
typedef std::tr1::function<void (void* frame, int len)> DoFrameFn; 

class CDevVS890
{
public:
    CDevVS890();

    void receive();   

    DoFrameFn m_callback_fn;
}

"CDevVS890.cpp"
void CDevVS890::receive()
{
    ...
    m_callback_fn((void*)frame, (int)len);
}

/*----------------------------------------------------------------------*/

"CVS890Executor.h"
class CVS890Executor
{
public:
    CVS890Executor();

private:
    void hookup_to_DevVS890();
    void do_full_frame( void* frame, int len );
}

"CVS890Executor.cpp"
CVS890Executor::CVS890Executor()
{
    hookup_to_DevVS890();
}

void CVS890Executor::hookup_to_DevVS890()
{
m_pDevVS890 = new CDevVS890();
m_pDevVS890->m_callback_fn = 
    std::tr1::bind(&CVS890Executor::do_full_frame, this, _1);
}

void CVS890Executor::do_full_frame(void* frame, int len)
{
   ...
}

错误很多,很难阅读:

在/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c /4.4.6/tr1/functional:56中包含的文件中,来自.. /../src/Common/CDevVS890.h:17,来自CVS890Executor.h:13,来自CVS890Executor.cpp:8:/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../ .. /../../include/c /4.4.6/tr1_impl/functional:在成员函数âtypenamestd:: tr1 :: result_of <Functor(typename std :: tr1 :: result_of 0)>( Bound_args,std :: tr1 :: tuple <_UElements ...>)> :: type ...)> :: type std :: tr1 :: _ Bind <_Functor(_Bound_args ...)> :: __ call(const std :: tr1 ::元组<_UElements ...>&,std :: tr1 :: _ Index_tuple <_Indexes ...>)[with _Args = void *&,int&,int ... _ Indexes = 0,1,_Functor = std :: tr1: :_Mem_fn,_Bound_args = CVS890Executor *,std :: tr1 :: _ Placeholder <1>]â:/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../ include / c /4.4.6/tr1_impl/functional:1191:从âtypenamestd:: tr1 :: result_of <Functor(typename std :: tr1 :: result_of 0)>( Bound_args,std :: tr1 :: tuple <_UElements)实例化...>)> :: type ...)> :: type std :: tr1 :: _ Bind <Functor(Bou nd_args ...)> :: operator()( Args&...)[with _Args = void *,int,_Functor = std :: tr1 :: _ Mem_fn,_Bound_args = CVS890Executor *,std :: tr1 :: _ Placeholder <1 >] us / usr / lib / gcc / x86_64 -redhat-linux /4.4.6 /../../../../include/c /4.4.6/tr1_impl/functional:1668:从âstaticVoid实例化std :: tr1 :: _ Function_handler :: _ M_invoke(const std :: tr1 :: _ Any_data&, ArgTypes ...)[与_Functor = std :: tr1 :: _ Bind(CVS890Executor *,std :: tr1 :: _ Placeholder <1> )>,_ ArgTypes = void *,int] /usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c /4.4.6/tr1_impl/ functional:2005:从âstd:: tr1 :: function <_Res(_ArgTypes ...)> :: function(_Functor,typename __gnu_cxx :: __ enable_if <(!)实例化 . std :: tr1 :: is_integral :: value),std :: tr1 :: function <_Res(_ArgTypes ...)> :: Useless> :: _ type)[with Functor = std :: tr1 :: _ Bind(CVS890Executor * ,std :: tr1 :: _ Placeholder <1>)>, Res = void,_ ArgTypes = void *,int] /usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../ . ./../include/c /4.4.6/tr1_impl/functional:1885:从âtypename__gnu_cxx :: __ enable_if <(!std :: tr1 :: is_integral :: value)实例化,std :: tr1 :: function <_Res (ArgTypes ...)>&> :: _ type std :: tr1 :: function <_Res(ArgTypes ...)> :: operator =( Functor)[with Functor = std :: tr1 :: _ Bind(CVS890Executor *, std :: tr1 :: _ Placeholder <1>)>, Res = void,_ArgTypes = void *,int] CVS890Executor.cpp:115:从这里实例化/usr/lib/gcc/x86_64-redhat-linux/4.4.6 /../../../../include/c /4.4.6/tr1_impl/functional:1137:错误:无法匹配调用â(std :: tr1 :: _ Mem_fn)(CVS890Executor *&,void &)â/ usr / lib / gcc / x86_64-redhat-linux /4.4.6 /../../../../include/c /4.4.6/tr1_impl/functional:546:note:candidate是:Res std :: tr1 :: _ Mem_fn <Res(Class :: *)( ArgType s ...)> :: operator()( Class&, ArgTypes ...)const [with _Res = void,_Class = CVS890Executor,_ArgTypes = void *,int] / usr / lib / gcc / x86_64-redhat-linux / 4.4.6 /../../../../ include / c /4.4.6/tr1_impl/functional:551:注意:Res std :: tr1 :: _ Mem_fn <Res(Class :: *)( ArgTypes ...)> :: operator()( Class *, ArgTypes ...)const [with _Res = void,_Class = CVS890Executor,_ArgTypes = void *,int] / usr / lib / gcc / x86_64-redhat-linux / 4.4.6 /../../../../ include / c /4.4.6/tr1_impl/functional:1137:错误:带有值的return语句,在函数返回'void' make: [CVS890Executor.o ]错误1

知道这有什么问题吗?

干杯

2 回答

  • 0

    你忘记了第二个论点 . 你对 bind 函数的调用应该是这样的:

    std::tr1::bind(&CVS890Executor::do_full_frame, this, _1, _2);
    //                                                       ^^
    
  • 1

    在CVS890Executor :: hookup_to_DevVS890()中,您没有将任何参数绑定到成员函数do_full_frame .

    您还尝试将函数的返回值赋给m_callback_fn,但声明do_full_frame()返回void(无返回值) .

相关问题