1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#include <iostream>
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
class A
{
boost::asio::deadline_timer timer_;
int count_;
A(void){timer_.async_wait(boost::bind(&A::print, this));}
void print()
{
if (count_ < 5)
{
std::cout << count_ << "\n";
++count_;
timer_.expires_at(timer_.expires_at() + boost::posix_time::seconds(10));
timer_.async_wait(boost::bind(&printer::print, this));
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
boost::asio::io_service io;
A p(io);
io.run();
cout<<"END";
return 0;
} |
Partager