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)
- fill in C++ STL
- Conditional or Ternary Operator (?:) in C/C++
- forward_list insert_after() function in C++ STL
- Count of distinct remainders when N is divided by all the numbers from the range [1, N]
- C++ | asm declaration
- Pointers and References in C++
- Strings in C++ and How to Create them?
- Enum Classes in C++ and Their Advantage over Enum DataType
- Deque vs Vector in C++ STL