13

I have seen the syntax below in many places where STL classes are used without explicitly qualifying them with std::. What is the advantage of the initial namespace std {}? Why not just put using namespace std;?

namespace std {}
using namespace std;
2
  • 3
    @Steephen: What? How? The OP's question is not addressed at all in that "duplicate", as far as I can tell. Commented Jul 5, 2015 at 0:37
  • @BenjaminLindley You are right, I didn't read question clearly. Reverted my closing vote. Commented Jul 5, 2015 at 0:41

1 Answer 1

10

namespace std {} simply declares the namespace so that the compiler knows about it and doing using namespace std; won't cause an error.

Later in the code stuff from std:: can be #included and they can be automatically referred to without the std:: prefix.

Sign up to request clarification or add additional context in comments.

1 Comment

That would mean the includes come after the using directive, which is a very bad thing to do - it can change the meaning of code in those headers!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.