[英]boost does not accept anonymous functions as input for anything
以下代碼段無法為我編譯:
#include <iostream>
#include <boost/thread.hpp>
int main(int argc, char* argv[])
{
boost::thread thread(
[]() {
std::cout<<"hello";
}
);
}
與錯誤:
no matching function for call to ‘boost::thread::thread(main(int, char**)::<lambda()>)’
我覺得我在這里犯了一個非常愚蠢的錯誤,但是已經有一段時間了,但我仍然找不到它。
您需要通過引用捕獲io_service
以獲得上述代碼片段進行編譯:
void start_thread(boost::asio::io_service &io_service)
{
boost::thread tcp_thread(
[&io_service]() { // <-- you missed a & here
io_service.run();
}
);
}
請注意, io_service
不實現復制語義。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.