Undefined Behavior with the C++0x Closure: I

后端 未结 3 1201
野趣味
野趣味 2021-01-19 19:17

Consider the example:

#include 
#include      // std::function
#include         // std::vector
#include 

        
3条回答
  •  一向
    一向 (楼主)
    2021-01-19 19:51

    (Edit: this certainly does not explain the ICE; I read the original question too hastily.)

    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.

提交回复
热议问题