在学习boost::asio时,第一次使用,编译出现问题:
代码如下:
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include <iostream>
void handle1(const boost::system::error_code &ec)
{
std::cout << "handle1" << "5 s" << std::endl;
}
void handle2(const boost::system::error_code &ec)
{
std::cout << "handle2" << "5 s" << std::endl;
}
boost::asio::io_service _io_server_;
void fun()
{
_io_server_.run();
}
int main(int argc, char *argv[])
{
boost::asio::deadline_timer time1_(_io_server_,boost::posix_time::seconds(5));
time1_.async_wait(handle1);
boost::asio::deadline_timer time2_(_io_server_,boost::posix_time::seconds(5));
time2_.async_wait(handle2);
boost::thread thread1_(fun);
boost::thread thread2_(fun);
thread1_.join();
thread2_.join();
return 0;
}
编译时打印的问题如下: