I have the following code:
DisplayObject conveyor_belts[] = {eggs_1, eggs_2, flour_1, flour_2, sugar_1, sugar_2, butter_1, butter_2};
std::thread conveyor_belts_t[4];
for (int j = 0; j < 4; j++) {
conveyor_belts_t[j] = std::thread([&](){
conveyor_belts[j * 2].draw(15, 78 + i * 3); // segmentation fault here
});
}
I defined a copy constructor for displayObject, but the code above gives me segmentation fault at the line highlighted. I can resolve this issue in the following way:
DisplayObject conveyor_belts[] = {eggs_1, eggs_2, flour_1, flour_2, sugar_1, sugar_2, butter_1, butter_2};
std::thread conveyor_belts_t[4];
for (int j = 0; j < 4; j++) {
conveyor_belts_t[j] = std::thread([&](){
conveyor_belts[0].draw(15, 78 + i * 3);
});
}
I wonder why a variable indexing will give me segmentation fault