O'Reilly logo

C++ Common Knowledge: Essential Intermediate Programming by Stephen C. Dewhurst

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

Item 23. Namespaces

Global scope was getting overly crowded. Everybody and his brother implemented libraries that reused the same names for different classes and functions. For example, many libraries wanted to include a class named String, but if you used two different libraries that defined a String type, you’d get a multiple definition error or worse. Various extra-language approaches used to address this problem (naming conventions, the preprocessor, ...) only made things worse. Namespaces to the rescue.

In some ways, namespaces introduce complexity (see Argument Dependent Lookup [25, 89]), but most uses of namespaces are simple and simplifying. A namespace is a subdivision of global scope:

This code snippet opens a namespace called

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