StackOverflow like this上还有其他解决方案,它们建议将boost :: function转换为函数指针。但是相同的代码会为我生成错误。我是否需要介绍reinterpret_cast
或者有更清洁的原因?
以下是生成错误的示例代码:
void
Do ( int (*callback) (MYType1 const*, MYType2* ) )
{
MYType2 tmp;
boost:: function <int(MYType1 const*)> fun = boost::bind( callback, _1, &tmp );
// My intention is to create c style function pointer out of `fun`
// but below line is generating error:
// error: cannot convert 'boost::function < int () (const MYType1*), std::allocator<void> >' to 'int (*)(const MYType1*)' in initialization
int (*c)(MYType1 const*) = &fun;
}