【发布时间】:2014-06-11 18:27:18
【问题描述】:
我正在尝试对我正在编写的一些代码采用功能性方法。特别是,我想将一个函数传递给另一个对其执行某些操作的函数,然后在boost::asio::io_service 上安排后一个函数。
我尝试了以下方法(受io_service.hpp 对io_service::post 的定义启发)为template <typename CompletionHandler> void post(CompletionHandler handler);):
#include <stdio.h>
#include <boost/asio/io_service.hpp>
#include <boost/bind.hpp>
template <typename FUNC>
void foo_then_smile(FUNC handler) {
handler();
printf("Smile!\n");
}
void foo(int a, int b, int c) {
printf("The important answer is %d\n", a + b + c);
}
int main() {
boost::asio::io_service ioService;
ioService.post(boost::bind(foo_then_smile, boost::bind(foo, 1, 2, 3)));
return 0;
}
但我明白了:
no matching function for call to 'bind(<unresolved overloaded function type>, boost::_bi::bind_t<void, void (*)(int, int, int), boost::_bi::list3<boost::_bi::value<int>, boost::_bi::value<int>, boost::_bi::value<int> > >)'
紧随其后的是大量候选人。
【问题讨论】:
标签: c++ function boost functional-programming boost-bind