C ++ using namespace declaration

So, for a while I used ...

using namespace::std; 

and recently I realized that there should be

 using namespace std; 

Can someone explain to me why I worked, and how it differs from the correct way to declare the use of a specific namespace?

+4
source share
1 answer

The first version works because the compiler sees it as

 using namespace ::std; // Notice space^ 

It just tells the compiler to look for the std in the global scope.

The scope operator :: without any left parts is the same as the global scope.

+7
source

Source: https://habr.com/ru/post/1487515/


All Articles