Function Returning Itself

后端 未结 9 724
鱼传尺愫
鱼传尺愫 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:12

    There's a way, you just try this:

    typedef void *(*FuncPtr)();
    
    void *f() { return f; }
    
    int main() {
        FuncPtr f1 = f();
        FuncPtr f2 = f1();
        FuncPtr f3 = f2();
        return 0;
    }
    

提交回复
热议问题