我正在尝试使用C++ 11中的std :: thread.如果可以在执行其某个函数成员的类中使用std :: thread,我找不到任何地方.考虑下面的例子......在我的尝试(下面)中,函数是run().
我使用-std = c ++ 0x标志用gcc-4.4编译.
#ifndef RUNNABLE_H
#define RUNNABLE_H
#include <thread>
class Runnable
{
public:
Runnable() : m_stop(false) {m_thread = std::thread(Runnable::run,this); }
virtual ~Runnable() { stop(); }
void stop() { m_stop = false; m_thread.join(); }
protected:
virtual void run() = 0;
bool m_stop;
private:
std::thread m_thread;
};
class myThread : public Runnable{
protected:
void run() { while(!m_stop){ /* do something... */ }; }
};
#endif // RUNNABLE_H
Run Code Online (Sandbox Code Playgroud)
我收到这个错误和其他人:(有和没有$ this相同的错误)
Runnable.h|9|error: no matching function for …Run Code Online (Sandbox Code Playgroud)