Passing member function as callback to shared library function

Is there a simple way to pass the current instance of a non-static member function as a callback function in a shared library? The following structure returns "invalid use of non-static member function"

1
2
3
4
5
6
7
8
9
10
11
12
class c{
  int bar (int a){
  ...
  }

  int lib_f{
  return shared_library_function(6, bar) 
  //shared_library_function(int a, (*cb)(int)) is the syntax, I want it to
  //invoke bar from the current object with parameter a.
  
  }
}
Your member functions may be understood as
1
2
//return_type name(class * const this, params)
int bar(c * const this, int a);
then you should realize that the signature don't match with the one expected by the callback.

To allow user data, the library function may be something like
shared_library( int a, void (*f)(int, void*), void *user_data);

As to how to solve it, I don't know. You may set a global pointer to your object, but it seems to much error-prone.
Topic archived. No new replies allowed.