1

There are other solutions on StackOverflow like this which suggest same way of converting boost::function into function pointer. But the same code generates error for me. Do I need to introduce reinterpret_cast or there is a cleaner why of doing this?

Below is the sample code which generates error:

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;
}
Community
  • 1
  • 1
Vishnu Kanwar
  • 761
  • 5
  • 22
  • possible duplicate of [demote boost::function to a plain function pointer](http://stackoverflow.com/questions/282372/demote-boostfunction-to-a-plain-function-pointer) – Jonathon Reinhart Nov 15 '13 at 05:50
  • @Jonathon Reinhart: why this assignment (initialization of 'c') is generating error while it is same as the solution you pointed? – Vishnu Kanwar Nov 15 '13 at 06:09
  • 3
    It looks like you haven't understood the post you linked to. As that post says, there isn't a way to get a function pointer from a boost::function in all cases. In your code, how is a C-style function pointer supposed to know about tmp? – chwarr Nov 15 '13 at 06:17

0 Answers0