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: 在成员函数中 â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: 实例化自 â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 ...)>::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: 从 â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:从âstd::tr1::function<_Res(_ArgTypes ...)>::function(_Functor, typename __gnu_cxx::__enable_if<(!std::tr1::is_integral::value), std::tr1:: 实例化函数<_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 = 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:注意:候选人是:_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: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'的函数中:* [CVS890Executor.o] 错误 1

知道这有什么问题吗?

干杯

4

2 回答 2

1

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

std::tr1::bind(&CVS890Executor::do_full_frame, this, _1, _2);
//                                                       ^^
于 2013-05-01T11:22:29.367 回答
0

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

您还尝试将函数的返回值分配给 m_callback_fn 但 do_full_frame() 被声明为返回 void (无返回值)。

于 2013-05-01T11:28:21.973 回答