17. Namespaces

Always design a thing by considering it in its next larger context.

Eliel Saarinen

Global scope problems — ideals for a solution — namespaces, using-declarations, and using-directives — how to use namespaces — name-spaces and classes — C compatibility.

17.1 Introduction

C provides a single global namespace for all names that don’t conveniently fit into a single function, a single struct, or a single translation unit. This causes problems with name clashes. I first grappled with this problem in the original design of C++ by defaulting all names to be local to a translation unit and requiring an explicit extern declaration to make them visible to other translation units. As described in §3.12, this idea was neither sufficient ...

Get The Design and Evolution of C++, First 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.