how to pass a non static-member function as a callback?

后端 未结 8 569
深忆病人
深忆病人 2020-12-07 01:59

 
io_iterator_t enumerator;
kern_return_t   result;
result = IOServiceAddMatchingNotification(
             mNotifyPort,
             kIOMatchedNotification,
             


        
8条回答
  •  囚心锁ツ
    2020-12-07 02:34

    Not directly.

    The non-static function pointer (known as a member function pointer) has a hidden 'this' parameter so the types don't match. The static function has no 'this' pointer.

    To get around this, you need to be able to pass in a user data item which is the 'this' pointer of the object you want to use as a callback. Then, specify a static member that is passed the user data, converts it to a pointer to the class object and calls the non-static member on it.

    Looking at the code you've posted, it's hard to tell if there is a user data object, possibly the last-but=one parameter.

提交回复
热议问题