How can I pass a class member function as a callback?

前端 未结 12 1937
忘掉有多难
忘掉有多难 2020-11-22 04:58

I\'m using an API that requires me to pass a function pointer as a callback. I\'m trying to use this API from my class but I\'m getting compilation errors.

Here is

12条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 05:50

    A pointer to a class member function is not the same as a pointer to a function. A class member takes an implicit extra argument (the this pointer), and uses a different calling convention.

    If your API expects a nonmember callback function, that's what you have to pass to it.

提交回复
热议问题