В «Букваре C++» Стэнли Липпмана на странице 234 упоминается, что
Обычно объявлять функцию локально — плохая идея. Однако
чтобы объяснить, как область видимости взаимодействует с перегрузкой, мы нарушим эту
практику и будем использовать объявления локальных функций.
< предварительно>
Код: Выделить всё
...
void print(const string &);
void print(double); // overloads the print function
void fooBar(int ival)
{ ...
// bad practice: usually it's a bad idea to declare functions at local scope
void print(int); // new scope: hides previous instances of print
print(ival); // ok: print(int) is visible
print(3.14); // ok: calls print(int); print(double) is hidden
}
I recall similar code in Scheme:
Код: Выделить всё
(define (PowerSet set)
(if (null? set) '(())
(let ((PowerSetAfterHead (PowerSet (cdr set) ) ))
(append PowerSetAfterHead
(PowerSet (cdr set) )
(map
(lambda (subset)
(cons (car set) subset
)
)
(PowerSet (cdr set) )
)
)
)
)
)
Источник: https://stackoverflow.com/questions/278 ... r-function