2
int Foo(int x) {
}

int Thing::Foo(int x) {
}

I'm trying to call a function that expects a void* InCallback, when I call it as Function(Foo) it does work.

When I try to call it Function(Thing::Foo) i get this error:

argument of type "int (Thing::*)(int x)" is incompatible with parameter of type "void *"

Is possible somehow to call the class function?

9
  • And what the value of this should be in that call? How would you pass that value even theoretically? If this is not actually used in Thing::Foo(), just make it static. Commented Sep 17, 2021 at 13:25
  • @Evg sorry, i don't understand your question. Commented Sep 17, 2021 at 13:28
  • 1
    To call Thing::Foo(), you need two values: int argument and this pointer to an object. When a callback void(int) is called via a function pointer, only int is passed to it. What about this? How could it be passed? Commented Sep 17, 2021 at 13:30
  • void* InCallback is not a function pointer. The code is already suspect, since function pointers and data pointers are not interchangeable. Your Thing::Foo is probably not marked static in the declaration. If it were, the code should work (ignoring the data pointer and function pointer conflation). Commented Sep 17, 2021 at 13:33
  • You mean that Function is declared as <some type> Function(void *)? Commented Sep 17, 2021 at 13:41

0