3: Whenever a name x defined in the standard library is mentioned, the name x is assumed to be fully qualified as ::std::x, unless explicitly described otherwise. For example, if the Effects section for library function F is described as calling library function G, the function ::std::G is meant.
I was reading the standard, and came across this. I noticed that the std namespace was fully qualified to reference the "global" std namespace. While I realize it is probably overkill to do it in an everyday program ("::std::string myString"), I asked myself this question: Can it even serve a use to fully qualify std? I know the standard makes it illegal to put anything inside the std namespace (except for full template sepcializations), so is there a point?
Can you think of a case where writing ::std would be mandatory?
Is your question related to IO?
Read this C++ FAQ LITE article at parashift by Marshall Cline. In particular points 1-6.
It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.
I suppose it may be necessary if someone has created a 'std' namespace within another namespace.
This won't compile without the :: qualifier.
Code:
#include <algorithm>
namespace application
{
namespace std
{
}
}
using namespace application;
int main()
{
int a[10];
::std::distance(&a[0], &a[10]);
}
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
I suppose it may be necessary if someone has created a 'std' namespace within another namespace.
This won't compile without the :: qualifier.
Code:
#include <algorithm>
namespace application
{
namespace std
{
}
}
using namespace application;
int main()
{
int a[10];
::std::distance(&a[0], &a[10]);
}
I had thought of that, but that would be the only case right? Besides, are you even allowed to do that?
Is your question related to IO?
Read this C++ FAQ LITE article at parashift by Marshall Cline. In particular points 1-6.
It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.
Is your question related to IO?
Read this C++ FAQ LITE article at parashift by Marshall Cline. In particular points 1-6.
It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.
Bookmarks