Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ using namespace declaration

So for a while I've been using...

using namespace::std;

and recently I realized that's supposed to be

using namespace std;

Can somebody explain to me why what I was doing worked, and how it differs from the correct way of declaring the usage of a certain namespace?

like image 395
kikiotsuka Avatar asked Mar 24 '23 11:03

kikiotsuka


1 Answers

The first version works because the compiler sees it as

using namespace ::std;
// Notice space^

That is simply telling the compiler to look for the name-space std in the global scope.

The scope operator :: without anything on the left-hand side is the same as the global scope.

like image 93
Some programmer dude Avatar answered Mar 31 '23 19:03

Some programmer dude