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 :
C++ Code :
Source code file
Error: Call of overloaded print() is ambiguous.
To overcome this situation, we use namespace objects independently
through scope resolution operator.
Source code file
Advance sub-domains of namespace :https://www.geeksforgeeks.org/namespace-in-c-set-2-extending-namespace-and-unnamed-namespace/https://www.geeksforgeeks.org/namespace-c-set-3-creating-header-nesting-aliasing-accessing/
This article is contributed by Rohit Thapliyal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- namespace in C++ | Set 2 (Extending namespace and Unnamed namespace)
- Namespace in C++ | Set 1 (Introduction)
- Why "using namespace std" is considered bad practice
- Difference between namespace and class
- Namespace in C++ | Set 3 (Accessing, creating header, nesting and aliasing)
- Difference between Virtual function and Pure virtual function in C++
- cin get() in C++ with Examples
- Difference between Increment and Decrement Operators
- Map of Vectors in C++ STL with Examples
- Problem in comparing Floating point numbers and how to compare them correctly?
- exit(0) vs exit(1) in C/C++ with Examples
- C++ program to print all Even and Odd numbers from 1 to N
- Reverse the content of a file and store it in another
- Minimum cells to be flipped to get a 2*2 submatrix with equal elements