C++/C function pointers that return void*

前端 未结 6 1339
故里飘歌
故里飘歌 2020-11-28 14:57

I\'m trying to call a function that takes an argument, void(*)(void*, int, const char*), but I cannot figure out how to pass those arguments to the function.

6条回答
  •  醉话见心
    2020-11-28 15:19

    The usual trick is to use a typedef for signature:

     typedef void signature_t (void*, int, const char*);
    

    Notice that without the typedef the syntax is like a function declaration. It declares signature_t as a typedef for functions, so you'll always use pointers to signature_t in practice.

    Then you can declare your "high-order" function as

     int function (int, int, signature_t*);
    

    See also this reply.

提交回复
热议问题