Passing member function pointer to the c-style function

前端 未结 3 882
慢半拍i
慢半拍i 2021-01-17 09:52

I am trying to pass member function pointer to the c-style function (as it\'s lib in C)

The pointer it wants is defined as:

void (*)(int, const char*         


        
3条回答
  •  情书的邮戳
    2021-01-17 10:21

    Not directly, no. A C++ member function needs an implicit this pointer, which of course C has no idea about and won't pass.

    The usual way around this is to introduce a "trampoline" as a class method, but perhaps there are prettier ways in more modern C++ variants.

提交回复
热议问题