gpt4 book ai didi

c++ - boost::bind 与 boost::asio 一起。 boost::bind 不起作用,从示例中复制

转载 作者:搜寻专家 更新时间:2023-10-31 01:13:34 26 4
gpt4 key购买 nike

有人能告诉我为什么这不能编译吗?我基本上是从 Kholkoff ( http://lists.boost.org/Archives/boost/2007/04/120339.php ) 的一个例子中复制的,早在 2007 年,关于 reads() in sockets with timeouts:

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

我像这样绑定(bind)()它:

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

gcc 打印的错误对我来说是不可读的:

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

最佳答案

那怎么样

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

setResult 是成员函数,如果你在 CClient 中使用 async_wait,或者使用一些 CClient 类型的对象而不是 this

关于c++ - boost::bind 与 boost::asio 一起。 boost::bind 不起作用,从示例中复制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12364625/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com