blob: 7545bbfdd3c7c1406651b51d77439f3cc7fa4947 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
<html>
<head>
<title>Apache Qpid : NoUsingNamespaceInHeaders</title>
<link rel="stylesheet" href="styles/site.css" type="text/css" />
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<table class="pagecontent" border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#ffffff">
<tr>
<td valign="top" class="pagebody">
<div class="pageheader">
<span class="pagetitle">
Apache Qpid : NoUsingNamespaceInHeaders
</span>
</div>
<div class="pagesubheading">
This page last changed on Oct 19, 2006 by <font color="#0050B2">mmccorma</font>.
</div>
<p>Don't use the{{using namespace ...}} or <tt>using ...</tt> constructs in a header file. It might save you some typing but it also forces the namespaces you use onto every <tt>.cpp</tt> file that directly or indirectly includes your headers. That could create name clashes with names in some other namespace that the author of the <tt>.cpp</tt> file wants to use. Use fully qualified names, painful as it might be.</p>
<p>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 <tt>std::tr1::auto_ptr</tt> template, which is used in qpid. <a href="http://www.boost.org" title="Visit page outside Confluence">Boost</a> does provide a compatible <tt>boost::auto_ptr</tt> but it's in the boost namespace and qpid expects it in <tt>std::tr1</tt>. No problem, we create our own tr1/memory header file:</p>
<div class="code"><div class="codeContent">
<pre class="code-java">#include <boost/memory>
namespace std {
namespace tr1 {
using boost::auto_ptr;
}
}</pre>
</div></div>
<p>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.)</p>
</td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td height="12" background="border/border_bottom.gif"><img src="border/spacer.gif" width="1" height="1" border="0"/></td>
</tr>
<tr>
<td align="center"><font color="grey">Document generated by Confluence on Apr 22, 2008 02:47</font></td>
</tr>
</table>
</body>
</html>
|