1

StackOverflow 上还有其他类似的解决方案,它们建议将 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;
}
4

0 回答 0