- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Cons of using the whole namespace in C++
In C++, we use different namespaces. We can also create our own namespaces. For example, generally, we use standard namespace called std. We write the syntax like:
using namespace std;
In the standard library, it contains common functionality you use in building your applications like containers, algorithms, etc. If names used by these were out in the open, for example, if they defined a queue class globally, you'd never be able to use the same name again without conflicts. So they created a namespace, std to contain this change.
The using namespace statement just means that in the scope it is present, make all the things under the std namespace available without having to prefix std:: before each of them.
While this practice is okay for example code, pulling in the entire std namespace into the global namespace is not good as it defeats the purpose of namespaces and can lead to name collisions. This situation is called namespace pollution.
- The Pros and Cons of Using Ajax
- Namespace in C++
- System.Reflection namespace in C#
- Why “using namespace std” is considered bad practice in C++
- What does 'using namespace std' mean in C++?
- What is the equivalent of C# namespace in Java?
- What are the pros and cons of using Python in competitive programming?
- What are the pros and cons of using Python vs. Java?
- Why the use of "using namespace std' considered bad practice?
- Extending namespace and Unnamed namespace
- Difference between namespace and class in C++
- Conversion of whole String to uppercase or lowercase using STL in C++
- The Pros and Cons of Investing in an Index Fund
- Pros and Cons of Mixed Economy
- Difference between namespace in C# and packages in Java