我正在为here指定的异步计时器运行简单的示例程序。
#include <iostream>
#include <boost/asio.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
void print()
{
std::cout << "Hello, world!" << std::endl;
}
int main()
{
boost::asio::io_service io;
boost::asio::deadline_timer t(io,boost::posix_time::seconds(5));
t.async_wait(&print);
io.run();
return 0;
}
在编译时,出现以下错误:
/boost/asio/basic_deadline_timer.hpp:实例化为“ void
boost :: asio :: basic_deadline_timer :: async_wait(const WaitHandler&)[with WaitHandler = void
(*)();时间= boost :: posix_time :: ptime; TimeTraits =
boost :: asio :: time_traits; TimerService =
boost :: asio :: deadline_timer_service>]’:
src / TimerTest.cpp:16:21:从这里需要
boost / 1.48.0 / common / include / boost / asio / detail / handler_type_requirements.hpp:250:43:
错误:函数的参数过多
boost :: asio :: detail :: lvref(handler)(\
我已经在网上狩猎了很长一段时间,但是找不到遇到类似错误的人。知道我该如何解决吗?
最佳答案
功能应具有签名:
void handler(
const boost::system::error_code& error // Result of operation.
);
您可以阅读in documentation
因此,只需修改您的
print
函数void print(const boost::system::error_code& ec)
{
std::cout << "Hello, world!" << std::endl;
}
关于c++ - Boost的编译错误basic_deadline_timer,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33032822/