Function pointers working as closures in C++

前端 未结 4 1415
情书的邮戳
情书的邮戳 2021-01-19 13:53

Is there a way in C++ to effectively create a closure which will be a function pointer? I am using the Gnu Scientific Library and I have to create a gsl_function. This funct

4条回答
  •  迷失自我
    2021-01-19 14:22

    I'm guessing from all those "gsl_" prefixes that the library is not C++, but plain C. Which means it doesn't grok C++ closures (functors). You can't pass a C++ functor to a C function. You'll have to pass void pointers around, cross your fingers and reinterpret_cast them into C oblivion.

提交回复
热议问题