且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用C ++ 0x闭合的未定义行为:I

更新时间: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.