클래스 이름 앞에 붙는 ::는 뭔가요?
조회수 3544회
::Configuration * tmpCo = m_configurationDB;//pointer to current db
제가 이런 코드를 봤는데
도대체 ::
이게 뭘 하는 건지 알 수가 없어요
::
를 지우면
declaration of tmpCo as a pointer to an object of the class Configuration
이런 게 떠요.
1 답변
-
지금 위치의
namespace
가 아니라global namespace
만 쓰고 싶을 때 맨 앞에::
를 붙입니다.예를 들어, 다음과 같이 서로 다른
Configuration
클래스가 있다고 하면class Configuration; // global namespace에 있는 class 1 namespace MyApp { class Configuration; // class1과 다른 namespace에 있는 class 2 function blah() { Configuration::doStuff(...) // MyApp::Configuration, class 2 ::Configuration::doStuff(...) // top-level Configuration, class 1 } }
이렇게, 다른
namespace
에서 같은 이름을 쓰고 있을 때namespace
를 한정하기 위해 쓰는 거죠
댓글 입력