Nested functions are not allowed but why nested function prototypes are allowed? [C++]

后端 未结 6 1465
余生分开走
余生分开走 2020-12-30 12:57

I was reading the linked question which leads me to ask this question.

Consider the following code

int main()
{
    string SomeString();
}
         


        
6条回答
  •  独厮守ぢ
    2020-12-30 13:28

    Just as a side note, C++03 does have a roundabout way of defining local functions. It requires abusing the local-class feature:

    int main()
    {
        struct Local
        {
            static string Some()
            {
                return "";
            }
        };
        std::cout << Local::Some() << std::endl;
    }
    

提交回复
热议问题