Search code examples
c++typesboost-thread

boost::thread_group::create_thread(<unresolved overloaded function type> error


I have a below tcpserver class file. When I create an instance of it in my main class and run it I get "unresolved function type" error in boost_group::create_thread function. I have no idea what's the reason. I tried changing methods to "const" but no luck. any help appriciated.

void tcpserver::WorkerThread() const
{
printf("test");
//  std::cout << "Thread Start\n";
//  io_service.run();
//  std::cout << "Thread Finish\n";
}

void tcpserver::StartServer() const {

    boost::shared_ptr< boost::asio::io_service::work > work(
        new boost::asio::io_service::work( io_service )
    );

    std::cout << "Press [return] to exit." << std::endl;

    boost::thread_group worker_threads;
    for( int x = 0; x < 4; ++x )

    {
        worker_threads.create_thread( WorkerThread);
    }

    std::cin.get();

    io_service.stop();

    worker_threads.join_all();


}

Solution

  • You are using a member function to create threads. Look at this: Start thread with member function

    In general, a member function needs an object to operate, if it is not a static member. You may also use a closure (lambda) of course.