59. Don’t write namespace using
s in a header file or before an #include
Summary
Namespace using
s are for your convenience, not for you to inflict on others: Never write a using
declaration or a using
directive before an #include
directive.
Corollary: In header files, don’t write namespace-level using
directives or using
declarations; instead, explicitly namespace-qualify all names. (The second rule follows from the first, because headers can never know what other header #include
s might appear after them.)
Discussion
In short: You can and should use namespace using
declarations and directives liberally in your implementation files after #include
directives and feel good about it. Despite repeated assertions to the contrary, namespace using ...
Get C++ Coding Standards: 101 Rules, Guidelines, and Best Practices 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.