Can a lambda expression be passed as function pointer?

后端 未结 5 1929
忘掉有多难
忘掉有多难 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:37

    You can use std::function for this:

    void fptrfunc(std::function fun, int j)
    {
        fun(j);
    }
    

    Or go completely generic:

    template 
    void fptrfunc(Fun fun, int j)
    {
        fun(j);
    }
    

提交回复
热议问题