C++ Namespaces


What are Namespaces?

  • In C++, namespaces allow us to group named entities that have global scope into narrower scope giving them namespace scope.
  • It is like a container for identifiers and it put the name of its members in a distinct space so that they don’t conflict with the names in other namespaces or global namespace.
  • Namespaces are used to organize too many classes so that it is easy to handle the application. The class of a namespace can be accessed by using namespacename::classname.

Let us understand namespace through an example:

Rules for declaring Namespace

  • Its declarations appear only at global scope.
  • Its declarations can be nested within another namespace.
  • Its declarations don’t have access specifiers (public or private).
  • In this we do need to give a semicolon after the closing brace of definition.


Share this website !!!
Facebook Twitter Linkedin