Passing capturing lambda as function pointer

前端 未结 9 2231
-上瘾入骨i
-上瘾入骨i 2020-11-21 06:58

Is it possible to pass a lambda function as a function pointer? If so, I must be doing something incorrectly because I am getting a compile error.

Consider the follo

9条回答
  •  醉梦人生
    2020-11-21 07:25

    As it was mentioned by the others you can substitute Lambda function instead of function pointer. I am using this method in my C++ interface to F77 ODE solver RKSUITE.

    //C interface to Fortran subroutine UT
    extern "C"  void UT(void(*)(double*,double*,double*),double*,double*,double*,
    double*,double*,double*,int*);
    
    // C++ wrapper which calls extern "C" void UT routine
    static  void   rk_ut(void(*)(double*,double*,double*),double*,double*,double*,
    double*,double*,double*,int*);
    
    //  Call of rk_ut with lambda passed instead of function pointer to derivative
    //  routine
    mathlib::RungeKuttaSolver::rk_ut([](double* T,double* Y,double* YP)->void{YP[0]=Y[1]; YP[1]= -Y[0];}, TWANT,T,Y,YP,YMAX,WORK,UFLAG);
    

提交回复
热议问题