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 ...
Get C++ Primer Plus 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.