This question already has an answer here:
I saw some code like this:
class MyThreadClass
{
public:
DoThread()
{
thread t(&MyThreadClass::ThreadFunc, this);
}
private:
ThreadFunc()
{
memberVar = 99;
}
int memberVar;
};
I'm confused how this works, since ThreadFunc is not passed a this pointer. And when I try to implement it, I get this:
warning C4573: the usage of 'MyThreadClass::memberVar' requires the compiler to capture 'this' but the current default capture mode does not allow it
I don't understand what "default capture mode" is in this context since all my search results turn up questions about lambda functions ([&,this] etc). Is it a compiler switch?
Aucun commentaire:
Enregistrer un commentaire