使用tr1 :: function时编译错误

时间:2013-05-01 10:47:55

标签: c++ compilation functor tr1

目的是在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&lt; _Functor(typename std :: tr1 :: result_of 0)&gt;(_ Bound_args,std :: tr1 :: tuple&lt; _UElements ...&gt;)&gt; :: type ...)&gt; :: type std :: tr1 :: _ Bind&lt; _Functor(_Bound_args ...)&gt; :: __ call(const std :: tr1 :: tuple&lt; _UElements ...&gt;&amp;,std :: tr1 :: _ Index_tuple&lt; _Indexes ... &gt;)[with _Args = void *&amp;,int&amp;,int ... _ Indexes = 0,1,_Functor = std :: tr1 :: _ Mem_fn,_Bound_args = CVS890Executor *,std :: tr1 :: _ Placeholder&lt; 1&gt; ]一个: /usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/tr1_impl/functional:1191:从âtypenamestd:: tr1实例化:: result_of&lt; _Functor(typename std :: tr1 :: result_of 0)&gt;(_ Bound_args,std :: tr1 :: tuple&lt; _UElements ...&gt;)&gt; :: type ...)&gt; :: type std :: tr1 :: _ Bind&lt; _Functor(_Bound_args ...)&gt; :: operator()(_ Args&amp; ...)[with _Args = void *,int,_Functor = std :: tr1 :: _ Mem_fn,_Bound_args = CVS890Executor *,std :: tr1 :: _占位符&lt; 1&gt;]â /usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/tr1_impl/functional:1668:从âstaticvoidstd实例化:: tr1 :: _ Function_handler :: _ M_invoke(const std :: tr1 :: _ Any_data&amp;,_ ArgTypes ...)[with _Functor = std :: tr1 :: _ Bind(CVS890Executor *,std :: tr1 :: _ Placeholder&lt; 1&gt;)&gt ;,_ 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&lt; _Res(_ArgTypes ...)&gt; :: function(_Functor,typename __gnu_cxx :: __ enable_if&lt;(!std :: tr1 :: is_integral :: value),std :: tr1 :: function&lt; _Res(_ArgTypes。 ..)&gt; :: 无用的&gt; :: _type)[与_Functor = std :: tr1 :: _ Bind(CVS890Executor *,std :: tr1 :: _ Placeholder&lt; 1&gt;)&gt;,_ 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&lt;实例化;(!std :: tr1 :: is_integral :: value),std :: tr1 :: function&lt; _Res( ArgTypes ...)&gt;&amp;&gt; :: _type std :: tr1 :: function&lt; _Res(_ArgTypes ...)&gt; :: operator =(_ Functor)[with _Functor = std :: tr1 :: _ Bind(CVS890Executor *,std :: tr1 :: _ Placeholder&lt; 1&gt;)&gt;,_ 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 *&amp;,void *&amp;)â /usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/tr1_impl/functional:546:注意:候选人是:_Res std :: tr1 :: _ Mem_fn&lt; _Res(_Class :: *)(_ ArgTypes ...)&gt; :: operator()(_ Class&amp;,_ 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&lt; _Res(_Class :: *)(_ ArgTypes ...)&gt; :: 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-statement with a值,在函数返回'void' make: * [CVS890Executor.o]错误1

知道这有什么问题吗?

干杯

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

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

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