Namespaces (using - namespace의 특정 맴버)
2024. 8. 3. 11:52ㆍ프로그래밍 언어/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
* using [namespace 맴버]
- using ns-name :: member-name ;
using 선언을 통해서 특정 네임스페이스 내의 특정 멤버를 현재 스코프로 가져온다. 명시적인 네임스페이스 접두사 없이 해당 멤버를 바로 사용할 수 있다.
예시 (ChatGPT 생성):
#include <iostream>
namespace A {
void foo() {
std::cout << "Function foo in namespace A" << std::endl;
}
void bar() {
std::cout << "Function bar in namespace A" << std::endl;
}
}
int main() {
using A::foo; // A::foo를 현재 스코프로 가져옴
foo(); // A::foo() 호출
// bar()는 여전히 A::bar()로 호출해야 함
A::bar();
return 0;
}
'프로그래밍 언어 > C++' 카테고리의 다른 글
데이터 타입 (C++) (0) | 2025.01.04 |
---|---|
std::is_empty - empty class (C++11~) (0) | 2024.08.04 |
Namespaces (using) (0) | 2024.08.03 |
Namespaces (스코프) (0) | 2024.08.02 |
Namespaces (익명 네임스페이스) (0) | 2024.07.30 |