Question

I am trying to create a thread which is running the IO service of boost's asio. However, I got the following compilation error. Is there any way to solve it?

Environment: gcc 4.7.2, boost 1.54

error: left operand of comma operator cannot resolve address of overloaded function
error: invalid static_cast from type ‘boost::asio::io_service’ to type ‘size_t (boost::asio::io_service::*)() {aka long unsigned int (boost::asio::io_service::*)()}’

Code:

boost::asio::io_service oSer;
    std::thread t(std::bind(static_cast<size_t (boost::asio::io_service::*)()>(&boost::asio::io_service::run, oSer)));
    t.join();
Was it helpful?

Solution

How about using lambda expression?

std::thread t([&oSer](){ oSer.run(); });

If you don't like to use lambda, try this

std::thread t(std::bind(static_cast<size_t(boost::asio::io_service::*)()>(&boost::asio::io_service::run), &oSer));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top