VOOZH about

URL: https://www.geeksforgeeks.org/cpp/cons-using-whole-namespace-c/

⇱ Cons of using the whole namespace in C++ - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Cons of using the whole namespace in C++

Last Updated : 15 Jun, 2017
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
Comment
Article Tags:
Article Tags: