Can we have functions inside functions in C++?

后端 未结 12 2305
抹茶落季
抹茶落季 2020-11-22 14:51

I mean something like:

int main() 
{
  void a() 
  {
      // code
  }
  a();

  return 0;
}
12条回答
  •  佛祖请我去吃肉
    2020-11-22 15:44

    All this tricks just look (more or less) as local functions, but they don't work like that. In a local function you can use local variables of it's super functions. It's kind of semi-globals. Non of these tricks can do that. The closest is the lambda trick from c++0x, but it's closure is bound in definition time, not the use time.

提交回复
热议问题