id:hito_hppさんに聞いて知ったのですが、
Boost Vaultにあるc_functionを使うと、関数オブジェクトを関数ポインタに変換してくれます。
#include <iostream> #include "c_function.hpp" struct functor { void operator()(int x) const { std::cout << x << std::endl; } }; void callback(void(*f)(int)) { (*f)(3); } int main() { using redshift::base::make_c_function; callback(make_c_function<struct call_0, void(*)(int)>(functor())); // 3 }
make_c_functionの型指定がめんどくさいけど便利ですね。
【参考】
muddy brown thang - C関数レベルのクロージャを C++ で実現?