2.8 Naming collisions and an introduction to namespaces

주홍영·2022년 3월 11일
0

Learncpp.com

목록 보기
32/199

https://www.learncpp.com/cpp-tutorial/naming-collisions-and-an-introduction-to-namespaces/

identifier의 unique한 속성의 당위성에 대해서 이야기한다

만약 동일한 identifier의 함수가 있다면 compile과정에서 문제가 생기지 않는다
하지만 linker가 실행되며 definition을 찾는 과정에서 혼선이 생긴다
복수의 선택지 중 어떠한 선택지를 call해야할지 정할 수가 없기 때문에 error을 뱉는다

*참고 : 함수가 불리지 않더라도 error가 발생한다는 점 명심

What is a namespace?

A namespace is a region that allows you to declare names inside of it for the purpose of disambiguation. The namespace provides a scope region (called namespace scope) to the names declared inside of it

namespace는 이러한 ambiguity를 해소할 수 있는 훌륭한 수단이다

단어장

abort : 중단하다
analogy : 비유
ex) Back to our address analogy for a moment
discourage : 막다 말리다 <-> encourage : 독려하다
ex) compiles but strongly discouraged, uninitialized variable definition in the global namespace

이러한 namespace의 예시로 std가 있다
우리는 std namespace를 사용할 때 명시적인 방법으로는 std::~로 사용할 수 있다
그리고 이러한 std::를 생략하고 사용하는 방법으로

Using namespace std;

와 같은 방법으로 생략해서 사용할 수 있다.

하지만 using을 쓰면 모호성이 발생해 에러가 발생할 수 있다

profile
청룡동거주민

0개의 댓글