简体   繁体   English

使用tr1 :: function时发生编译错误

[英]Compilation Error when using tr1::function

The purpose is to execute CVS890Executor::do_full_frame when calling the m_callback_fn within CDevVS890. 目的是在CDevVS890中调用m_callback_fn时执行CVS890Executor :: do_full_frame。

Following is the incriminated code: 以下是该代码:

"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)
{
   ...
} 

The errors are multiple and very difficult to read: 这些错误是多重的,很难理解:

In file included from /usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/tr1/functional:56, from ../../src/Common/CDevVS890.h:17, from CVS890Executor.h:13, from CVS890Executor.cpp:8: /usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/tr1_impl/functional: In member function âtypename std::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::tuple<_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: instantiated from âtypename std::tr1::result_of<_Functor(typename std::tr1::result_of 0)>(_Bound_args, std::tr1::tuple<_UElements ...>)>::type ...)>::type std::tr1::_Bind<_Functor(_Bou 在/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 :: tuple <_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>]â /usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/tr1_impl/functional:1668: instantiated from âstatic void std::tr1::_Function_handler::_M_invoke(const std::tr1::_Any_data&, _ArgTypes ...) [with _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: instantiated from âstd::tr1::function<_Res(_ArgTypes ...)>::function(_Functor, typename __gnu_cxx::__enable_if<(! nd_args ...)> :: operator()(_ Args&...)[with _Args = void *,int,_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:1668:从“静态无效”实例化std :: tr1 :: _ Function_handler :: _ M_invoke(const std :: tr1 :: _ Any_data&,_ArgTypes ...)[with _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/ function:2005:从std :: tr1 :: function <_Res(_ArgTypes ...)> :: function(_Functor,类型名__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: instantiated from â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: instantiated from here /usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/tr1_impl/functional:1137: error: no match for call to â(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: candidates are: _Res std::tr1::_Mem_fn<_Res (_Class::*)(_Arg std :: tr1 :: is_integral :: value),std :: tr1 :: function <_Res(_ArgTypes ...)> :: 无用> :: _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 =无效,_ArgTypes =无效*,整数] – 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 *&)的调用不匹配*&)â/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/tr1_impl/functional:546:注意:候选是:_Res std :: tr1 :: _ Mem_fn <_Res(_Class :: *)(_ Arg Types ...)>::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: note: _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: error: return-statement with a value, in function returning 'void' make: * [CVS890Executor.o] Error 1 类型...)> :: 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:错误:函数中返回“ void”的返回值带有make: * [CVS890Executor .o]错误1

Any idea what's wrong with this? 知道这有什么问题吗?

Cheers 干杯

You forgot about the second argument. 您忘记了第二个论点。 Your call of bind function should be like this: 您对bind函数的调用应如下所示:

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

In CVS890Executor::hookup_to_DevVS890(), you are not binding any arguments to the member function do_full_frame. 在CVS890Executor :: hookup_to_DevVS890()中,您没有将任何参数绑定到成员函数do_full_frame。

You are also trying to assign the return value of the function to m_callback_fn but do_full_frame() is declared to return void (no return value). 您还试图将函数的返回值分配给m_callback_fn,但是do_full_frame()被声明为返回void(无返回值)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM