Lambda of a lambda : the function is not captured

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

The following program do not compile :

#include 
#include 
#include 
#include 
#include 

        
相关标签:
2条回答
  • 2021-02-03 21:30

    You use the f parameter in the lambda inside asort(), but you don't capture it. Try adding f to the capture list (change [] to read [&f]).

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题