Lambda of a lambda : the function is not captured

前端 未结 2 1752
无人共我
无人共我 2021-02-03 21:29

The following program do not compile :

#include 
#include 
#include 
#include 
#include 

        
2条回答
  •  情书的邮戳
    2021-02-03 21:50

    You are effectively referencing f, which is a variable in the outer scope, in your lambda. You should capture it in your capture list (simplest is probably by reference [&f], or [&] to capture everything by reference, as you are using it immediately).

    On another note, std::function has some overhead as it performs type erasure, in your case here it might be better to introduce a template type.

提交回复
热议问题