C++ c++;线程函数指针实现返回错误。非静态成员函数的使用无效

C++ c++;线程函数指针实现返回错误。非静态成员函数的使用无效,c++,multithreading,C++,Multithreading,我已经试着掌握线程的诀窍有一段时间了,但是无论我看了多少例子或类似的SOflow问题,似乎都没有什么能启发我找到答案。我需要从类的构造函数中调用类的成员函数作为线程 我尝试过各种不同的更改(其中很少有我真正理解的目的,因为我是线程新手——对不起,伙计们!),例如将目标函数设置为静态(这导致在它的位置上发生大量错误——尽管它似乎解决了无效使用) 到目前为止,我得到的基本信息是: class VideoController { VideoController() {

我已经试着掌握线程的诀窍有一段时间了,但是无论我看了多少例子或类似的SOflow问题,似乎都没有什么能启发我找到答案。我需要从类的构造函数中调用类的成员函数作为线程

我尝试过各种不同的更改(其中很少有我真正理解的目的,因为我是线程新手——对不起,伙计们!),例如将目标函数设置为静态(这导致在它的位置上发生大量错误——尽管它似乎解决了无效使用)

到目前为止,我得到的基本信息是:

class VideoController
{
    VideoController()
    {
        //initialise everything else
        std::thread t(VideoController::Heartbeat)//originally: t(Heartbeat);
        //                                       //and have tried: (Heartbeat, NULL);
    }

    void Heartbeat() //tried: static void Heartbeat() && void Heartbeat(void)
    {
        while(true) //(why threading is essential)
        {
            //carry out function
        }
    }
}
这给我的错误是:
VideoController.cpp:在构造函数“VideoController::VideoController(std::u-cx11::string,std:u-cx11::string,std:u-cx11::string)”中:
VideoController.cpp:115:49:错误:无效使用非静态成员函数“void VideoController::Heartbeat()”

std::线程t(心跳)




如果有人能告诉我一些关于为什么这对我不起作用的事情,我将不胜感激

class A
{
  void threadfunc() { ... }

  void foo()
  { 
       std::thread t(&A::threadfunc,this);
       ... 
  }
};

使用成员函数创建线程时,还必须传递
this
(因为所有非静态成员函数都将指向该类的隐藏指针作为其第一个参数)

除了传递
这个
,我还错过了符号和引用。非常感谢你,迈克尔!