범위 지정 연산자 ( :: )

함수나 변수명 등을 namespace에 따라 구분할 때 사용

 

namespace

영역이라는 말 그대로 변수나 함수들이 선언된 범위, 묶음 이라고 생각하면 된다.

 

사용법

#include<iostream>
#include<string>
using namespace std;

namespace A{
  int test = 2;
  void hello(){
    cout << "I am A" << endl;
  }
}

namespace B{
  void hello(){
    cout << "I am B" << endl;
  }
}

int main(){
  A::hello();
  B::hello();
  cout << A::test << endl;
}

 

+ Recent posts