因此C ++应用程序中有一个function<void(void)>
引用的非静态成员函数。我需要使用boost::asio::deadline_timer.async_wait(callback)
通过升压计时器来调用它。目前timer.async_wait(callback)
给出了此错误
In file included from /usr/include/boost/asio/impl/io_service.hpp:18:0,
from /usr/include/boost/asio/io_service.hpp:767,
from /usr/include/boost/asio/basic_io_object.hpp:19,
from /usr/include/boost/asio/basic_socket.hpp:20,
from /usr/include/boost/asio/basic_datagram_socket.hpp:20,
from /usr/include/boost/asio.hpp:21,
from /home/foo/NetBeansProjects/ceuis-g3/Timer.h:20,
from /home/foo/NetBeansProjects/ceuis-g3/Timer.cpp:9:
/usr/include/boost/asio/basic_deadline_timer.hpp: In instantiation of ‘typename boost::asio::async_result<typename boost::asio::handler_type<ConnectHandler, void(boost::system::error_code)>::type>::type boost::asio::basic_deadline_timer<Time, TimeTraits, TimerService>::async_wait(WaitHandler&&) [with WaitHandler = std::function<void()>&; Time = boost::posix_time::ptime; TimeTraits = boost::asio::time_traits<boost::posix_time::ptime>; TimerService = boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> >; typename boost::asio::async_result<typename boost::asio::handler_type<ConnectHandler, void(boost::system::error_code)>::type>::type = void]’:
/home/foo/NetBeansProjects/ceuis-g3/Timer.cpp:24:29: required from here
/usr/include/boost/asio/basic_deadline_timer.hpp:505:5: error: static assertion failed: WaitHandler type requirements not met
BOOST_ASIO_WAIT_HANDLER_CHECK(WaitHandler, handler) type_check;
^
/usr/include/boost/asio/basic_socket.hpp:754:5: error: no match for call to ‘(std::function<void()>) (const boost::system::error_code&)’
BOOST_ASIO_CONNECT_HANDLER_CHECK(ConnectHandler, handler) type_check;
^
In file included from /usr/include/c++/7/functional:58:0,
from /home/foo/NetBeansProjects/ceuis-g3/Timer.h:18,
from /home/foo/NetBeansProjects/ceuis-g3/Timer.cpp:9:
/usr/include/c++/7/bits/std_function.h:701:5: note: candidate: _Res std::function<_Res(_ArgTypes ...)>::operator()(_ArgTypes ...) const [with _Res = void; _ArgTypes = {}]
function<_Res(_ArgTypes...)>::
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/7/bits/std_function.h:701:5: note: candidate expects 0 arguments, 1 provided
async_wait
的声明如下
template <typename WaitHandler>
BOOST_ASIO_INITFN_RESULT_TYPE(WaitHandler,
void (boost::system::error_code))
async_wait(BOOST_ASIO_MOVE_ARG(WaitHandler) handler)
我来自Java,我不知道这意味着什么。如何将一个成员表示转换成另一个成员表示?
编辑:答案在liliscent的评论中。