19.10 REMAINING TOPICS

19.10.1 Namespace

In large programs, we have large number of identifier. It is possible that there may be duplicate names for classes, functions, objects, types, etc. As we know, duplicate names are not allowed. Hence, the concept of namespace comes in. It is the synonymous of scope in C++. A typical declaration looks as

namespace [identifier] { namespace-body }

A namespace is a keyword. Optional identifier follows it. This identifier is the name of the namespace being declared. Namespace-body is a declarative region.

It goes without saying that declarations which are related to each other by some criterion are supposed to be placed in a namespace. Variables within the namespace are required to be unique. However, our program ...

Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.