Function Returning Itself

后端 未结 9 707
鱼传尺愫
鱼传尺愫 2020-11-27 04:59

Is it possible to declare some function type func_t which returns that type, func_t?

In other words, is it possible for a function to retur

9条回答
  •  迷失自我
    2020-11-27 05:29

    what about something like this:

    typedef void* (*takesDoubleReturnsVoidPtr)(double);
    
    void* functionB(double d)
    {
        printf("here is a function %f",d);
        return NULL;
    }
    
    takesDoubleReturnsVoidPtr functionA()
    {
        return functionB;
    }
    
    int main(int argc, const char * argv[])
    {
        takesDoubleReturnsVoidPtr func = functionA();
        func(56.7);
        return 0;
    }
    

提交回复
热议问题