2

Why C++ does not allow something like:

int foo(int x) {
    void bar(int x) { return x*x;}
    return bar(x);
}

Disclaimer: I am not asking for the rationale for disallowing it. We can define classes inside functions, in particular functors, and since C++11 lambdas, so actually I do not see the need for it.

However, I wonder if there is some technical limitation/problem that would prevent to allow it. Would it create ambiguities syntax-wise? Other problems that I dont see? Or is the answer perhaps simply: It is not allowed because there is no need for it?

463035818_is_not_an_ai
  • 109,796
  • 11
  • 89
  • 185

0 Answers0