문제

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();
도움이 되었습니까?

해결책

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));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top