Namespaces (익명 네임스페이스)
2024. 7. 30. 16:22ㆍ프로그래밍 언어/C++
참고: https://en.cppreference.com/w/cpp/language/namespace
Namespaces - cppreference.com
Namespaces provide a method for preventing name conflicts in large projects. Entities declared inside a namespace block are placed in a namespace scope, which prevents them from being mistaken for identically-named entities in other scopes. Entities declar
en.cppreference.com
* 익명 네임스페이스
- namespace { declarations }
선언된 파일 내에서만 유효한 식별자를 선언할 때 사용되고 'static' 키워드와 유사하게 생각하면 된다. 외부 파일에서 식별자 링크를 할 수 없다.
예시 (ChatGPT 생성):
namespace {
int hiddenValue = 100;
void showHiddenValue() {
std::cout << hiddenValue << std::endl;
}
}
int main() {
showHiddenValue(); // 100
}
'프로그래밍 언어 > C++' 카테고리의 다른 글
Namespaces (using - namespace의 특정 맴버) (0) | 2024.08.03 |
---|---|
Namespaces (using) (0) | 2024.08.03 |
Namespaces (스코프) (0) | 2024.08.02 |
Namespaces (인라인 네임스페이스) (0) | 2024.07.29 |
Namespaces (기본 네임스페이스) (0) | 2024.07.29 |