[英]boost does not accept anonymous functions as input for anything
The following code piece does not compile for me: 以下代码段无法为我编译:
#include <iostream>
#include <boost/thread.hpp>
int main(int argc, char* argv[])
{
boost::thread thread(
[]() {
std::cout<<"hello";
}
);
}
With the error : 与错误:
no matching function for call to ‘boost::thread::thread(main(int, char**)::<lambda()>)’
I feel like I am making a very stupid mistake here, but it has been sometime, and i still fail to find it. 我觉得我在这里犯了一个非常愚蠢的错误,但是已经有一段时间了,但我仍然找不到它。
You need to capture io_service
by reference to get the above code snippet to compile: 您需要通过引用捕获
io_service
以获得上述代码片段进行编译:
void start_thread(boost::asio::io_service &io_service)
{
boost::thread tcp_thread(
[&io_service]() { // <-- you missed a & here
io_service.run();
}
);
}
Note that the io_service
does not implement copy semantics. 请注意,
io_service
不实现复制语义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.