Returning function pointer type

前端 未结 7 1957
心在旅途
心在旅途 2020-11-29 20:08

Often I find the need to write functions which return function pointers. Whenever I do, the basic format I use is:

typedef int (*function_type)(int,int);

fu         


        
7条回答
  •  既然无缘
    2020-11-29 20:34

    ill leave this here since it was a bit trickier than answers already given, as it takes a function pointer

    (int (__cdecl *)(const char *))

    and returns a function pointer

    (int (__cdecl *)(const char *))

    #include 
    
    int (*idputs(int (*puts)(const char *)))(const char *) {
        return puts;
    }
    
    int main(int argc, char **argv)
    {
        idputs(puts)("Hey!");
    
        return 0;
    }
    

提交回复
热议问题