I have this constructor that initializes the bar
member with 0 and starts a thread:
Foo::Foo() :
bar(0)
{
std::thread threadloop = std::thread(loop); //create a thread with the loop function
threadloop.join();
}
And this loop()
function from the Foo class
:
void Foo::loop()
{
while (true)
{
bar++;
//do more stuff...
}
}
The compiler complains that the loop
method must be static
...
But if I put it static
, how can I access the Foo
private members that are not static
? (and must not be static).
EDIT:
If I use like this, it won't compile either:
std::thread threadloop(&Foo::loop, Foo());
Error: Use of deleted function.
I want to call this from my constructor
, and not from outside my class.