I have a function void f (void*, int);
, that is used as a callback function. The caller expects void (*)(int)
. Can I use std::bind1st
to convert one to another? Is there any way to do this without using C++ 11 std::bind
, just std::bind1st
?
Can std::bind1st be used to convert void (*)(void*,int) to void (*)(int)?
130 views Asked by Violet Giraffe At
1
No. Although
std::bind1st()
creates a function object with a call operator taking andint
, it is not avoid(*)(int)
. The only way to turn avoid(*)(void*, int)
into avoid(*)(int)
is to have a forwarding function which obtains thevoid*
from global resources, e.g.,Anybody providing a callback which doesn't take a user-defined context, e.g., in the C-like interface a
void*
which is just passed through, didn't think too hard about the interface.