boost::thread_group::create_thread(<unresolved overloaded function type> 错误
boost::thread_group::create_thread(<unresolved overloaded function type> error
我有一个下面的 tcpserver class 文件。当我在主 class 和 运行 中创建它的实例时,我在 boost_group::create_thread 函数中得到 "unresolved function type" 错误。我不知道是什么原因。我尝试将方法更改为 "const" 但没有成功。任何帮助适用。
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();
}
您正在使用成员函数创建线程。看这个:
Start thread with member function
一般情况下,成员函数需要一个对象来操作,如果不是静态成员的话。当然,您也可以使用闭包 (lambda)。
我有一个下面的 tcpserver class 文件。当我在主 class 和 运行 中创建它的实例时,我在 boost_group::create_thread 函数中得到 "unresolved function type" 错误。我不知道是什么原因。我尝试将方法更改为 "const" 但没有成功。任何帮助适用。
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();
}
您正在使用成员函数创建线程。看这个: Start thread with member function
一般情况下,成员函数需要一个对象来操作,如果不是静态成员的话。当然,您也可以使用闭包 (lambda)。