C++ function returning function

后端 未结 7 614
南笙
南笙 2020-12-24 12:13

Where in the standard are functions returning functions disallowed? I understand they are conceptually ridiculous, but it seems to me that the grammar would allow them. Acco

7条回答
  •  再見小時候
    2020-12-24 12:27

    in kinda sense,function_pointer is funciton its self,
    and "trailing return type" is a good and hiding thing in c++11,i will rather write like this:

    #include
    
    
    
    auto return0(void)->int
    {return 0;}
    auto returnf(void)->decltype(&return0)
    {return &return0;}
    
    
    
    /*Edit: or...
    auto returnf(void)->auto (*)(void)->int
    {return &return0;}
    //that star means function pointer
    */
    
    
    
    
    auto main(void)->int
    {
        std::cout<

    (if type unmatch,try apply address operator "&")
    look,so much of sense.

    but down side of this is that "auto" thing in head of function,
    that`s non-removable and no type could match it (even lambda could match template type std::function<>) but if you wish,macro could do magic(sometime curse) to you

    #define func auto
    

提交回复
热议问题