问题
I have been looking over some posts here on Stackoverflow, and I have noticed that most people use std::
but some people uses ::std::
I think i have read something about a global scope or something like that in namespaces as a reason to use ::std::
(but i can't find it now, because it was in a comment to an unrelated question)
Is there any reason to prefer one way versus the other?
回答1:
It's a bad idea to write code like this, but you could:
namespace foo {
namespace std {
int bar;
}
std::string s;
}
In that case, the std::string
refers to the ::foo::std
namespace, not the ::std
namespace. So, using ::std::string
is just being a little bit more unambiguously careful.
来源:https://stackoverflow.com/questions/18544651/on-namespace-names-std-vs-std