Differences between revisions 2 and 3
Revision 2 as of 2006-10-19 10:11:48
Size: 1168
Revision 3 as of 2009-09-20 23:51:27
Size: 1168
Editor: localhost
Comment: converted to 1.6 markup
No differences found!

MIGRATED to http://cwiki.apache.org/confluence/display/qpid/NoUsingNamespaceInHeaders

Don't use the using namespace ... or using ... constructs in a header file. It might save you some typing but it also forces the namespaces you use onto every .cpp file that directly or indirectly includes your headers. That could create name clashes with names in some other namespace that the author of the .cpp file wants to use. Use fully qualified names, painful as it might be.

There is one exception. It's sometimes handy to "import" names from one namespace to another. For example suppose some C++ compiler doesn't provide the std::tr1::auto_ptr template, which is used in qpid. [www.boost.org Boost] does provide a compatible boost::auto_ptr but it's in the boost namespace and qpid expects it in std::tr1. No problem, we create our own tr1/memory header file:

#include <boost/memory>
namespace std { 
  namespace tr1 {
    using boost::auto_ptr;

This makes the boost template available in the standard namespace. (Actually you don't need to do this yourself, boost provides a set of adapter headers for all the tr1 stuff.)

CppTips/NoUsingNamespaceInHeaders (last edited 2009-09-20 23:51:27 by localhost)