I am working on setting a member function as a callback for the C library I am using. The C library sets callbacks as follows:
typedef int (*functionPointer_t)(myType1_t*, myType2_t*, myType3_t*); setCallback(param1, param2, functionPointer, param4)
I would like to use boost :: bind (if possible) to pass a function pointer. I would prefer the specified function to be a member of the class instance, rather than a static member. For example.
Class A { public: A(); protected: int myCallback(myType1_t*, myType2_t*, myType3_t*);
Can this be done using boost :: bind and boost :: function? Per How do I pass a member function of a class as a callback? (third answer), it seems that I can declare the following (somewhere or as a typedef):
boost::function<int (A*, myType1_t*, myType2_t*, myType3*> myCallbackFunction
And then somewhere in (ctor) call boost :: bind of this type and pass it to the C library call.
Is this possible, or have I left the base? Many thanks.
c ++ boost boost-bind boost-function
jdt141
source share