Possible Duplicate:
Using std Namespace
I was just wondering if there was some reason to include std:: in some operations, like std::sort() for example. Is it because of possible overloading?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Apart from the usually well known reasons of polluting the current namespace with unnecessary symbol names and readability there is a subtle another reasoning.
Consider the example of std::swap,it is an standard library algorithm to swap two values. With Koenig algorithm/ADL one would have to be cautious while using this algorithm because:
may not show the same behavior as:
With ADL, which version of
swapfunction gets called would depend on the namespace of the arguments passed to it.If there exists an namespace
Aand ifA::obj1,A::obj2&A::swap()exist then the second example will result in a call toA::swap()which might not be what the user wanted.Further, if for some reason both:
A::swap(A::MyClass&, A::MyClass&)andstd::swap(A::MyClass&, A::MyClass&)are defined, then the first example will callstd::swap(A::MyClass&, A::MyClass&)but the second will not compile becauseswap(obj1, obj2)would be ambiguous.