boost::bind together with boost::asio. boost::bind not working, copied from an example

放肆的年华 提交于 2019-12-24 03:12:36

问题


Could someone tell me why this does not compile? I basically copied it from an example by Kholkoff (http://lists.boost.org/Archives/boost/2007/04/120339.php), back in 2007, about reads() in sockets with timeouts:

void CClient::setResult(boost::optional<boost::system::error_code>*
                         a,boost::system::error_code b)
{
    *a = b;
}

I'm binding() it like this:

timer.async_wait(boost::bind(&CClient::setResult, &timer_result, _1));

The errors that gcc prints are unreadable to me:

static assertion failed: WaitHandler type requirements not met  remote_server       line 499, external location: /usr/include/boost/asio/basic_deadline_timer.hpp   C/C++ Problem
no match for call to ‘(boost::_bi::bind_t<boost::_bi::unspecified, void (CClient::*)(boost::optional<boost::system::error_code>*, boost::system::error_code), boost::_bi::list2<boost::_bi::value<boost::optional<boost::system::error_code>*>, boost::arg<1> > >) (const boost::system::error_code&)’  remote_server       line 499, external location: /usr/include/boost/asio/basic_deadline_timer.hpp   C/C++ Problem
‘void (CClient::*)(boost::optional<boost::system::error_code>*, boost::system::error_code)’ is not a class, struct, or union type   remote_server       line 69, external location: /usr/include/boost/bind/bind.hpp    C/C++ Problem
make: *** No rule to make target `all'.             C/C++ Problem
make: *** [src/CClient.o] Error 1   remote_server           C/C++ Problem
  required from ‘class boost::_bi::bind_t<boost::_bi::unspecified, void (CClient::*)(boost::optional<boost::system::error_code>*, boost::system::error_code), boost::_bi::list2<boost::_bi::value<boost::optional<boost::system::error_code>*>, boost::arg<1> > >’  remote_server       line 15, external location: /usr/include/boost/bind/bind_template.hpp   C/C++ Problem
  required from here    CClient.cpp /remote_server/src  line 93 C/C++ Problem

回答1:


And how about

timer.async_wait(boost::bind(&CClient::setResult, this, &timer_result, _1));

setResult is member function, if you use async_wait in CClient, or use some object of type CClient instead of this.



来源:https://stackoverflow.com/questions/12364625/boostbind-together-with-boostasio-boostbind-not-working-copied-from-an-e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!