在单独的线程中运行类成员函数

时间:2019-03-22 22:08:06

标签: multithreading c++11 boost std-function stdbind

一天中的好时光!我正在将Visual Studio 2015与Boost 1.66一起使用。目前,我正在尝试使用boost在单独的线程中运行类成员函数。

void ServerWorkerTh()
{

}

void StartServer() const
{
    auto f = boost::bind(&NetworkCore::ServerWorkerTh, this);
    boost::thread th(f);
}

但是我得到

  

错误C2440:“参数”:无法从“ const NetworkCore”转换为   “ NetworkCore&”

似乎编译器希望接收对真实对象的引用,但实际上我是在给他this。是否可以在不使用lambda的情况下在单独的线程中运行类成员函数?

0 个答案:

没有答案
相关问题