C++ function returning function

后端 未结 7 625
南笙
南笙 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条回答
  •  萌比男神i
    2020-12-24 12:16

    using namespace std;
    
    auto hello()
    {
        char name[] = "asdf";
        return [&]() -> void
        {
            printf("%s\n", name);
        };
    }
    
    int main()
    {
        hello()();
        auto r = hello();
        r();
        return 0;
    }
    

提交回复
热议问题