【问题标题】:boost::thread_group::create_thread(<unresolved overloaded function type> errorboost::thread_group::create_thread(<未解决的重载函数类型> 错误
【发布时间】:2016-04-11 13:24:33
【问题描述】:

我有一个下面的 tcpserver 类文件。当我在我的主类中创建它的一个实例并运行它时,我在 boost_group::create_thread 函数中得到“未解析的函数类型”错误。我不知道是什么原因。我尝试将方法更改为“const”,但没有运气。任何帮助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();


}

【问题讨论】:

    标签: c++ types boost-thread


    【解决方案1】:

    您正在使用成员函数来创建线程。看这个: Start thread with member function

    一般来说,一个成员函数需要一个对象来操作,如果它不是一个静态成员的话。当然,您也可以使用闭包 (lambda)。

    【讨论】:

    • 更改了 create_thread 函数调用如下; worker_threads.create_thread([this] { WorkerThread(); });
    猜你喜欢
    • 2013-02-20
    • 2013-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多