【发布时间】:2013-11-23 03:52:11
【问题描述】:
这部分代码来自example:
int main()
{
boost::asio::io_service io;
printer p(io);
boost::thread t(boost::bind(&boost::asio::io_service::run, &io));
io.run();
t.join();
return 0;
}
如果我将boost::bind(&boost::asio::io_service::run, &io) 替换为std::bind(&boost::asio::io_service::run, &io),则会出现编译错误:
.../usr/lib/c++/v1/functional:1843:1: note: candidate template
ignored: couldn't infer template argument '_Fp'
bind(_Fp&& __f, _BoundArgs&&... __bound_args)
^
/usr/lib/c++/v1/functional:1852:1: note: candidate template
ignored: couldn't infer template argument '_Rp'
bind(_Fp&& __f, _BoundArgs&&... __bound_args)
^
1 error generated.
为什么会出现这个错误?
为什么std::bind(&printer::print1, &p) 有效,而std::bind(&boost::asio::io_service::run, &io) 无效?
【问题讨论】:
-
添加错误信息的所有行。
-
boost::thread有一个转发构造函数,所以你根本不需要绑定:boost::thread t(&boost::asio::io_service::run, &io);
标签: c++ boost c++11 bind boost-asio