C++/C function pointers that return void*

前端 未结 6 1336
故里飘歌
故里飘歌 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:32

    Unless I totally misinterpret your code, you are trying to pass a function pointer with an argument by doing

    function(20, 20, ptr(20));
    

    That is incorrect and illegal. In order to pass a function as a parameter into another function you have to follow the following syntax

    function(20, 20, &ptr); 
    
    or
    
    function(20, 20, ptr); 
    

    Even though I would recomment leaving the '&' for readability

提交回复
热议问题