このような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;
}