c++ - boost does not accept anonymous functions as input for anything -


the following code piece not compile me:

#include <iostream> #include <boost/thread.hpp>   int main(int argc, char* argv[]) {   boost::thread thread(                 []() {                     std::cout<<"hello";                 }             ); } 

with error :

no matching function call ‘boost::thread::thread(main(int, char**)::<lambda()>)’ 

i feel making stupid mistake here, has been sometime, , still fail find it.

you need capture io_service reference above code snippet compile:

void start_thread(boost::asio::io_service &io_service) {     boost::thread tcp_thread(         [&io_service]() {  // <-- missed & here             io_service.run();         }     ); } 

note io_service not implement copy semantics.


Comments

Popular posts from this blog

gcc - MinGW's ld cannot perform PE operations on non PE output file -

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

c# - Search and Add Comment with OpenXML for Word -