AshwinJaishanker
AshwinJaishanker

Reputation: 13

Compilation Error with Boost basic_deadline_timer

I'm running the simple example program for asynchronous timers given 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;
}

On compilation, I get the following error:

/boost/asio/basic_deadline_timer.hpp: In instantiation of ‘void boost::asio::basic_deadline_timer::async_wait(const WaitHandler&) [with WaitHandler = void (*)(); Time = boost::posix_time::ptime; TimeTraits = boost::asio::time_traits; TimerService = boost::asio::deadline_timer_service >]’:

src/TimerTest.cpp:16:21: required from here boost/1.48.0/common/include/boost/asio/detail/handler_type_requirements.hpp:250:43: error: too many arguments to function boost::asio::detail::lvref(handler)( \

I've hunted online for quite some time now but can't find anyone who has faced a similar error. Any idea how I can resolve this?

Upvotes: 1

Views: 955

Answers (1)

ForEveR
ForEveR

Reputation: 55887

Function should have signature:

void handler(
  const boost::system::error_code& error // Result of operation.
);

You can read it in documentation

So, just modify your print function

void print(const boost::system::error_code& ec)
{
    std::cout << "Hello, world!" << std::endl;
}

Upvotes: 0

Related Questions