Cons of using the whole namespace in C++ Last Updated : 15 Jun, 2017 Summarize Comments Improve Suggest changes Share Like Article Like Report A namespace is a declarative region that provides a scope to the identifiers (the names of types, functions, variables, etc) inside it. Namespaces are used to organise code into logical groups and to prevent name collisions that can occur especially when your code base includes multiple libraries. Please refer need of namespace in C++ for details. Suppose we need two header files for a software project : 1: Header1.h -namespace one 2: Header2.h -namespace two C++ Code : Header1.h : CPP namespace one { /*Function to print name of the namespace*/ void print() { std :: cout << "This is one" << std :: endl; } } Header2.h CPP namespace two { /*Function to print name of the namespace*/ void print() { std :: cout << "This is two" << std :: endl; } } Source code file CPP /*Including headers*/ #include <iostream> #include "Header1.h" #include "Header2.h" /*Using namespaces*/ using namespace std; using namespace one; using namespace two; /*Driver code*/ int main() { /*Ambiguity*/ print(); } Output: Error: Call of overloaded print() is ambiguous. To overcome this situation, we use namespace objects independently through scope resolution operator. Source code file CPP /*Including headers*/ #include <iostream> #include "Header1.h" #include "Header2.h" /*Driver code*/ int main() { /*Using function of first header*/ one :: print(); /*Using function of second function*/ two :: print(); } Reference : https://cplusplus.com/forum/beginner/25538/ https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice Advance sub-domains of namespace :https://www.geeksforgeeks.org/cpp/namespace-in-c-set-2-extending-namespace-and-unnamed-namespace/https://www.geeksforgeeks.org/cpp/namespace-c-set-3-creating-header-nesting-aliasing-accessing/ GeeksforGeeks Namespace archive Comment More infoAdvertise with us Next Article Why "using namespace std" is considered bad practice R Rohit Thapliyal Improve Article Tags : C++ cpp-namespaces Practice Tags : CPP Similar Reads Why "using namespace std" is considered bad practice The statement using namespace std is generally considered bad practice. The alternative to this statement is to specify the namespace to which the identifier belongs using the scope operator(::) each time we declare a type. Although the statement saves us from typing std:: whenever we wish to access 5 min read Can namespaces be nested in C++? In C++, namespaces can be nested, and resolution of namespace variables is hierarchical. For example, in the following code, namespace inner is created inside namespace outer, which is inside the global namespace. In the line "int z = x", x refers to outer::x. If x would not have been in outer then 2 min read Nested Inline Namespaces In C++20 The Inline Namespace is a feature that was first introduced in C++ 11. They can also be nested inside another namespace and the members of this nested namespace can be accessed as if they are the members of the parent namespace. Their syntax may seem complex so in C++20, a new version introduced a n 2 min read C++ Inline Namespaces and Usage of the "using" Directive Inside Namespaces Prerequisite: Namespaces in C++ In C++, namespaces can be nested, and the resolution of namespace variables is hierarchical. An inline namespace is a namespace that uses the optional keyword inline in its original-namespace definition. This allows the identifiers of the nested inline namespace to be 3 min read Namespace in C++ Name conflicts in C++ happen when different parts of a program use the same name for variables, functions, or classes, causing confusion for the compiler. To avoid this, C++ introduce namespace.Namespace is a feature that provides a way to group related identifiers such as variables, functions, and 6 min read Importance of Constructors in C++ Constructors are special member functions in C++ that are invoked automatically when an object of a class is created. Their primary role is to initialize objects. In this article, we will learn all the factors that makes the constructor important in C++.Table of ContentInitialization of ObjectsResou 8 min read Like