Question

The purpose is to execute CVS890Executor::do_full_frame when calling the m_callback_fn within CDevVS890.

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(_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: 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<(! 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::*)(_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: 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

Any idea what's wrong with this?

Cheers

Was it helpful?

Solution

You forgot about the second argument. Your call of bind function should be like this:

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

OTHER TIPS

In CVS890Executor::hookup_to_DevVS890(), you are not binding any arguments to the member function 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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top