O'Reilly logo

Just Enough C/C++ Programming by Guy W. Lecky-Thompson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Namespaces

Namespaces allow you to create groupings of identifiers that exist within a specific scope. This mechanism is incredibly useful because it allows you to include identifiers within a subprogram without worrying about duplicating them with code outside of that namespace.

So if you have a header file that defines a collection of routines and data types, you can contain them inside a namespace that refers to the purpose that they fulfill, without having to create a class specifically for them.

The namespace Keyword

You start a namespace with the namespace keyword. Everything in the code block that follows the keyword is considered to be a part of that namespace. So you might create a namespace in a header file as follows:

namespace ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required