This is for my actual project, but I made a minimal example (code is based on an example of Lightness Races in Orbit).
#include <thread>
#include <iostream>
class Foo
{
Foo(int n = 10)
{
size_t a[n];
constexpr int p = 5;
std::thread threads[p];
for (int i = 0; i < p; ++i)
threads[i] = std::thread(std::bind(&Foo::bar, this, a, n));
for (auto& th : threads) th.join();
}
void bar(size_t* a, int n) {}
};
int main() {std::cout << "ok\n";}
The error comes by the fact that I am using an array that has n as its size. However, it will be very difficult for me -in the real project- to change that, since many lines of code are based on that.
&a[0]?