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

后端 未结 6 1485
余生分开走
余生分开走 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:22

    This is a convention from C -- like many -- which C++ has adopted.

    The ability to declare a function inside another function in C is a decision that most programmers probably consider regrettable and unnecessary. Particularly with modern OOP design where function definitions are comparatively smaller than they are in C.

    If you would like to have functions that only exist in the scope of another function, two options are boost::lambda and C++1x lambda.

提交回复
热议问题