I want to be able to define a class with some data members, and a function which has access to those data members, which are to be private.
I then want a public function, which creates some threads, which operate on the data members of the class. I am having some trouble getting my code to compile.
Don't worry about mutex or data protection, this isn't going to be a problem, since this is just some example code for testing.
class foo {
public:
void make_foo_func_threads();
private:
void foo_func();
char private_data;
std::vector<std::thread> some_threads;
}
void foo::foo_func() {
while(1) {
private_data = 'A';
}
}
void foo::make_foo_func_thread() {
for(...) some_threads.push_back(std::thread(foo_func));
for(...) some_threads.join();
}
The compiler is giving me the error:
'no matching call to std::thread::thread()'
Apparently there is 'no known conversion for argument 1 from <unresolved overloaded function type>
to void (foo::*&&)'
.
Erm, yeah, I have no idea what that means apart from the compiler is having trouble understanding how to resolve foo_func - I think.
How can I help the compiler understand what I am trying to do, so it won't bother me with any more errors. No doubt the code I have written is not legal, and if that is the case could someone explain why that is the case to me. Thanks!