You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>With few exceptions, place code in a namespace. Namespaces
528
527
should have unique names based on the project name, and possibly
529
-
its path. Do not use <i>using-directives</i> (e.g.,
530
-
<code>using namespace foo</code>). Do not use
528
+
its path. Do not use <i>using-namespace</i>directives (e.g.,
529
+
<code>using namespace foo;</code>). Do not use
531
530
inline namespaces. For unnamed namespaces, see
532
531
<ahref="#Internal_Linkage">Internal Linkage</a>.
533
532
533
+
534
534
</p><pclass="definition"></p>
535
+
<h4>Using Declaration:</h4>
536
+
<p>Using declaration are allowed and can be used to refer to specific symbol from a namespace. For example</p>
537
+
<pre><code>Using ::foo::bar;</code></pre>
538
+
539
+
<h4>Additional Note With an Example:</h4>
540
+
541
+
<h5>Using NameSpace Directives: </h5>
542
+
<p>Using namespace directives brings the all the specified symbols/built-in-types from the specified NameSpace into the whatever current scope you are in, which leads to naming conflict and confusion(ambiguity). Therefore, they should be avoided.</p>
543
+
544
+
<p><strong>Example: </strong></p>
545
+
<pre><code>//Avoid This Practice:
546
+
using namespace std;
547
+
std::cout,std::endl or somethinglike std::string st = "Hello";</code></pre>
548
+
549
+
<h5>Using Declarations:</h5>
550
+
<p>Using Declarations allow you to bring namespace into current scope. This practice helps in avoiding the ambiguity(confusion) and which eventually keeps the code clear and manageable.</p>
551
+
<p><strong>Example to Use:</strong></p>
552
+
<pre><code>//Accepted
553
+
using namespace std;
554
+
cout,abs() or string str = "Hello,World";</code></pre>
555
+
535
556
<p>Namespaces subdivide the global scope
536
557
into distinct, named scopes, and so are useful for preventing
0 commit comments