How can I initialize a boost::function object with a raw function pointer?
Metacode
extern "C"
{
class Library
{
...
};
Library* createLibrary();
}
…
void* functionPtr = library.GetFunction("createLibrary");
boost::function<Library*()> functionObj(functionPtr);
Library* libInstance = functionObj();
If you need additional information’s just let me know.
void*is not a function pointer, so you can’t create aboost::functionfrom it. You probably want to convert this to a proper function pointer first. How to do that is implementation dependent.This is how this ugly conversion is recommended in POSIX (rationale):
Your platform may require different shenanigans.
Once you have such a pointer you can simply do: