Reputation: 309
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;
Upvotes: 13
Views: 324
Reputation: 42828
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 #include
d and they can be automatically referred to without the std::
prefix.
Upvotes: 10