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 :
Header2.h
Source code file
Output:
Error: Call of overloaded print() is ambiguous.
To overcome this situation, we use namespace objects independently
through scope resolution operator.
Source code file