Can a lambda expression be passed as function pointer?

后端 未结 5 1989
忘掉有多难
忘掉有多难 2021-02-05 02:49

I am trying to pass a lambda expression to a function that takes a function pointer, is this even possible?

Here is some sample code, I\'m using VS2010:

         


        
5条回答
  •  长发绾君心
    2021-02-05 03:30

    As long as the lambda doesn't use capture clause (i.e. doesn't capture variables from above it), it can be used as a function pointer. VC compiler internally generates anonymous functions with different calling convention so that it can be used without issues.

提交回复
热议问题