스탠리 리프만의 "C++ 프라이머는"페이지 (234)에서,이 의미는 함수의 몸체 내부에 함수를 선언, 그렇게 할 수있는 상황 그럼에도 불구하고C++ : 다른 함수 내에서 함수를 선언하는 용도는 무엇입니까?
Ordinarily, it is a bad idea to declare a function locally. However, to explain how scope interacts with overloading, we will violate this practice and use local function declarations.
...
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
}
, 언급?
나는 계획에 유사한 코드를 기억 :
(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))
)
)
)
)
)
는 일반적으로 외부 함수의 사용만을위한 의도 "로컬 기능"의 오용 숨기는 데 사용되어 있습니까? 내부 수업 같은 거요? 또는 일부 디자인 패턴에서 유용합니까?
"일반적으로 함수를 로컬로 선언하는 것은 좋지 않습니다." ;) –
특정 오버로드를 제외하고 모두 명시 적으로 숨기려면? –
캐스트를 사용하여 명시 적으로 선택하는 것이 더 좋은 생각 일 수도 있지만 ... – Deduplicator