首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Boost-asio deadline_timer运行时错误

Boost-asio deadline_timer运行时错误
EN

Stack Overflow用户
提问于 2014-08-06 20:11:06
回答 2查看 323关注 0票数 0

所以,我正在学习一个教程,试图设置一个基本的计时器.

代码语言:javascript
复制
void print(const boost::system::error_code &e)
{
  std::cout <<"hello world"<< std::endl;
}

int main()
{
  boost::asio::io_service io;
  boost::asio::deadline_timer timer(io, boost::posix_time::seconds(5));
  timer.async_wait(print);
  io.run();
}

构建良好,但在运行时;

代码语言:javascript
复制
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::system::system_error> >'
  what():  thread: The attempted operation is not supported for the type of object referenced

Win7,GCC,代码::blocks

编辑;在具有相同设置的另一台计算机上试用--相同的结果。

再次编辑;我是否应该从boost 1_47切换到最新版本?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-08-09 03:48:30

我切换了boost 1.56,它起作用了。

票数 0
EN

Stack Overflow用户

发布于 2014-08-07 05:41:09

您的代码适用于我,使用MinGw 4.8和boost 1.55。但是,尝试将对timer.async_wait的调用更改为:

代码语言:javascript
复制
#include <boost/bind.hpp>

timer.async_wait(boost::bind(&print, boost::asio::placeholders::error));
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25169325

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档