diff --git a/cppguide.html b/cppguide.html index 273d5d767..7fcb1fc55 100644 --- a/cppguide.html +++ b/cppguide.html @@ -498,7 +498,6 @@

Names and Order of Includes

#include <string> #include <vector> - #include "base/basictypes.h" #include "foo/server/bar.h" #include "third_party/absl/flags/flag.h" @@ -526,12 +525,34 @@

Namespaces

With few exceptions, place code in a namespace. Namespaces should have unique names based on the project name, and possibly -its path. Do not use using-directives (e.g., -using namespace foo). Do not use +its path. Do not use using-namespacedirectives (e.g., +using namespace foo;). Do not use inline namespaces. For unnamed namespaces, see Internal Linkage. +

+

Using Declaration:

+

Using declaration are allowed and can be used to refer to specific symbol from a namespace. For example

+
Using ::foo::bar;
+ +

Additional Note With an Example:

+ +
Using NameSpace Directives:
+

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.

+ +

Example:

+
//Avoid This Practice: 
+using namespace std;
+std::cout,std::endl or somethinglike std::string st = "Hello";
+ +
Using Declarations:
+

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.

+

Example to Use:

+
//Accepted 
+  using namespace std;
+  cout,abs() or string str = "Hello,World";
+

Namespaces subdivide the global scope into distinct, named scopes, and so are useful for preventing name collisions in the global scope.