0
代碼是在這裏Qt的使用lambda功能時
void A::fun()
{
QAction* act = new QAction(this);
QAction* act2 = new QAction(this);
connect(act, QAction::triggered, [this, &act2]() {...; act2.setDisable(true);}
// crash when &act2 is used to capture the variable
// but it is okay using act2 to capture the variable
}
的原因是什麼連接會崩潰嗎?謝謝。
它崩潰而不是給出編譯錯誤。爲什麼超出範圍?謝謝。 – user1899020
'act2'上的_object_不在範圍之外(它在堆上),但變量'act2'只在'fun()'範圍內。 – cmannett85