Namespaces and the Future
As programmers become more familiar with namespaces, common programming idioms will emerge. Here are some current guidelines:
• Use variables in a named namespace instead of using external global variables.
• Use variables in an unnamed namespace instead of using static global variables.
• If you develop a library of functions or classes, place them in a namespace. Indeed, C++ currently already calls for placing standard library functions in a namespace called std. This extends to functions brought in from C. For example, the math.c header file, which is C-compatible, doesn’t use namespaces, but the C++ cmath header file should place the various math library functions in the std namespace.
• Use the using directive only ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access