문제 설명
컴파일 시 변수의 이름과 수명 (Name and lifetime of variables at compile time)
내가 아는 모든 언어(Java, C++)에서 변수의 이름과 수명은 항상 컴파일 타임에 알려져 있습니다. 런타임에 이름과 수명이 바인딩되는 언어가 있습니까?
게다가 현재 C++ 스마트 포인터를 사용하고 있습니다. 수명과 범위는 언제 알 수 있나요?
참조 솔루션
방법 1:
With C++ smart pointers, the scope of the smart pointer is the regular scope. The scope of the managed object is determined by the smart pointers behavior.
There are a lot of languages that employ dynamic/runtime scoping. Javascript, PERL, PHP is a few. https://en.wikipedia.org/wiki/Scope_%28computer_science%29#Dynamic_scoping
방법 2:
with java, NO a priori , or very difficult
see this: Is it possible to create variables at runtime in Java?
What can you do with that at runtime ?
You can reference variables, as you want (in an array, integer, in a Map ...)
(by Bobby、Captain Giraffe、guillaume girod‑vitouchkina)