更新时间:2023-11-10 19:29:58
)
问题在于,从加法器
函数返回的lambdas包含对不再存在的 x
变量的悬挂引用。捕获副本( [=]
或 [i]
)而不是引用( &]
),一切都应该工作。
The One problem in that code is that the lambdas returned from the adder
function contain dangling references to the x
variable that no longer exists. Capture by copy ([=]
or [i]
) instead of a reference ([&]
) and everything should work.