the problem of class member function used as argument

Myclass.h file

1
2
3
4
5
6
7
8
9
10
class Myclass{
private:
      int i;

public:
 
      void call(int i, short s, void* v); 
      void start();
}


Myclass.cpp file

1
2
3
4
5
6
void Myclass::start(){
     ...
     event_set(ev, fd, EV_READ, call, NULL);
     ...
}


event_set()is a library API, which requires that the type of call() is void(*f)(int i,short s,
void* v)

but the type of call is void(*Myclass::f)(int i,short s, void* v)
if call() is a static member, since i is not static, it is not OK

how to deal with such a scenario?

can function pointer casting help solve the problem?
Last edited on
Create a static class function with the required signature. Instead of NULL you pass this as the last parameter of event_set(...). Within the static class function you can cast v -> this and call any non static member of the class you want.
Topic archived. No new replies allowed.