kikiotsuka
kikiotsuka

Reputation: 79

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?

Upvotes: 3

Views: 325

Answers (1)

Some programmer dude
Some programmer dude

Reputation: 409442

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.

Upvotes: 6

Related Questions