I'm trying to write a wrapper method set_timer() that takes a time and callback (expressed using boost::bind) and sets up a deadline_timer to run that callback.
The callback is real simple at the moment:
void foo::callback(const boost::system::error_code& error) {
std::cout << "callback" << std::endl;
}
For set_timer() I have:
void foo::set_timer(boost::posix_time::ptime time,
boost::function<void(const boost::system::error_code&)> handler) {
pimpl->t.expires_at(time);
pimpl->t.async_wait(handler);
}
And I'm trying to call it from within the foo object for now:
set_timer(boost::posix_time::seconds(1), boost::bind (&foo::callback, this));
Error message when compiling is:
foo.cpp: In member function ‘void foo::run()’:
foo.cpp:50: error: no matching function for call to ‘foo::set_timer(boost::posix_time::seconds, boost::_bi::bind_t<void (&)(const boost::system::error_code&), boost::_mfi::dm<void(const boost::system::error_code&), foo>, boost::_bi::list1<boost::_bi::value<foo*> > >)’
src/foo_sdr.cpp:43: note: candidates are: void foo::set_timer(boost::posix_time::ptime, boost::function<void(const boost::system::error_code&)>)
Looks like the signature is either much more complex or much simpler than I'm thinking.
I'd like to replace the callback signature with something like:
typedef std::function<void(const boost::system::error_code&)> timer_callback_t;
I'm on CentOS 6.6 with gcc 4.4.7 and -std=gnu++0x, so no access to auto
.
No luck working off How do you pass boost::bind objects to a function? or What is the return type of boost::bind?, and I don't understand what's different about my situation.