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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -