{"id":947,"date":"2018-01-01T02:42:25","date_gmt":"2018-01-01T01:42:25","guid":{"rendered":"https:\/\/rosetta.vn\/short\/2018\/01\/01\/namespaces-c\/"},"modified":"2018-06-13T13:01:42","modified_gmt":"2018-06-13T12:01:42","slug":"namespaces-c","status":"publish","type":"post","link":"https:\/\/rosetta.vn\/short\/2018\/01\/01\/namespaces-c\/","title":{"rendered":"Namespaces (C++)"},"content":{"rendered":"<blockquote>\n<p style=\"color: rgb(42, 42, 42); margin-bottom: 0px; padding-bottom: 15px; line-height: 18px; font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px;\">The latest version of this topic can be found at<a href=\"https:\/\/docs.microsoft.com\/cpp\/cpp\/namespaces-cpp\" style=\"color: rgb(0, 112, 159);\">Namespaces (C++)<\/a>.<\/p>\n<p style=\"color: rgb(42, 42, 42); margin-bottom: 0px; padding-bottom: 15px; line-height: 18px; font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px;\">A namespace is a declarative region that provides a scope to the identifiers (the names of types, functions, variables, etc) inside it. Namespaces are used to organize code into logical groups and to prevent name collisions that can occur especially when your code base includes multiple libraries. All identifiers at namespace scope are visible to one another without qualification. Identifiers outside the namespace can access the members by using the fully qualified name for each identifier, for example<code>std::vector&lt;std::string&gt; vec;<\/code>, or else by a<a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/was37tzw.aspx\" style=\"color: rgb(0, 112, 159);\">using Declaration<\/a><span class=\"Apple-converted-space\">&nbsp;<\/span>for a single identifier (<code>using std::string<\/code>), or a<span class=\"Apple-converted-space\">&nbsp;<\/span><a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/aewtdfs3.aspx\" style=\"color: rgb(0, 112, 159);\">using Directive<\/a><span class=\"Apple-converted-space\">&nbsp;<\/span>for all the identifiers in the namespace (<code>using namespace std;<\/code>). Code in header files should always use the fully qualified namespace name.<\/p>\n<p style=\"color: rgb(42, 42, 42); margin-bottom: 0px; padding-bottom: 15px; line-height: 18px; font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px;\">The following example shows a namespace declaration and three ways that code outside the namespace can accesses their members.<\/p>\n<p id=\"code-snippet-1\" class=\"codeSnippetContainer\" xmlns=\"\" style=\"min-width: 0px; clear: both; color: rgb(0, 0, 0); font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 17.55px;\">\n<p class=\"codeSnippetContainerTabs\" style=\"vertical-align: middle; height: 23px; position: relative; z-index: 1;\">\n<p class=\"codeSnippetContainerCodeContainer\" style=\"border: 1px solid rgb(147, 147, 147); clear: both; margin-bottom: 12px; position: relative; top: -1px;\">\n<p class=\"codeSnippetToolBar\" style=\"width: auto; height: auto;\">\n<p class=\"codeSnippetToolBarText\" style=\"float: right; top: -8px; position: relative; width: auto; padding-left: 0px; padding-right: 0px; height: 0px; vertical-align: top; background-color: rgb(255, 255, 255);\">\n<p id=\"CodeSnippetContainerCode_42de6951-72a0-43e8-87df-fa4b7c71e25d\" class=\"codeSnippetContainerCode\" dir=\"ltr\" style=\"width: auto; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 10px 21px;\">\n<p style=\"padding: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;\">\n<pre style=\"padding: 5px; margin-top: 0px; margin-bottom: 0px; overflow: auto; word-wrap: normal; font-family: Consolas, Courier, monospace !important;\">namespace ContosoData  \n{      \n    class ObjectManager   \n    {  \n    public:  \n        void DoSomething() {}  \n    };  \n    void Func(ObjectManager) {}  \n}  \n\n<\/pre>\n<\/p>\n<p style=\"color: rgb(42, 42, 42); margin-bottom: 0px; padding-bottom: 15px; line-height: 18px; font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px;\">Use the fully qualified name:<\/p>\n<p id=\"code-snippet-2\" class=\"codeSnippetContainer\" xmlns=\"\" style=\"min-width: 0px; clear: both; color: rgb(0, 0, 0); font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 17.55px;\">\n<p class=\"codeSnippetContainerTabs\" style=\"vertical-align: middle; height: 23px; position: relative; z-index: 1;\">\n<p class=\"codeSnippetContainerCodeContainer\" style=\"border: 1px solid rgb(147, 147, 147); clear: both; margin-bottom: 12px; position: relative; top: -1px;\">\n<p class=\"codeSnippetToolBar\" style=\"width: auto; height: auto;\">\n<p class=\"codeSnippetToolBarText\" style=\"float: right; top: -8px; position: relative; width: auto; padding-left: 0px; padding-right: 0px; height: 0px; vertical-align: top; background-color: rgb(255, 255, 255);\">\n<p id=\"CodeSnippetContainerCode_a50ba6c9-bf9f-4249-8747-a14560d7a746\" class=\"codeSnippetContainerCode\" dir=\"ltr\" style=\"width: auto; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 10px 21px;\">\n<p style=\"padding: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;\">\n<pre style=\"padding: 5px; margin-top: 0px; margin-bottom: 0px; overflow: auto; word-wrap: normal; font-family: Consolas, Courier, monospace !important;\">ContosoData::ObjectManager mgr;  \nmgr.DoSomething();  \nContosoData::Func(mgr);  \n\n<\/pre>\n<\/p>\n<p style=\"color: rgb(42, 42, 42); margin-bottom: 0px; padding-bottom: 15px; line-height: 18px; font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px;\">Use a using declaration to bring one identifier into scope:<\/p>\n<p id=\"code-snippet-3\" class=\"codeSnippetContainer\" xmlns=\"\" style=\"min-width: 0px; clear: both; color: rgb(0, 0, 0); font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 17.55px;\">\n<p class=\"codeSnippetContainerTabs\" style=\"vertical-align: middle; height: 23px; position: relative; z-index: 1;\">\n<p class=\"codeSnippetContainerCodeContainer\" style=\"border: 1px solid rgb(147, 147, 147); clear: both; margin-bottom: 12px; position: relative; top: -1px;\">\n<p class=\"codeSnippetToolBar\" style=\"width: auto; height: auto;\">\n<p class=\"codeSnippetToolBarText\" style=\"float: right; top: -8px; position: relative; width: auto; padding-left: 0px; padding-right: 0px; height: 0px; vertical-align: top; background-color: rgb(255, 255, 255);\">\n<p id=\"CodeSnippetContainerCode_90fbb0b4-a208-48ba-b33c-393ab8fc1c28\" class=\"codeSnippetContainerCode\" dir=\"ltr\" style=\"width: auto; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 10px 21px;\">\n<p style=\"padding: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;\">\n<pre style=\"padding: 5px; margin-top: 0px; margin-bottom: 0px; overflow: auto; word-wrap: normal; font-family: Consolas, Courier, monospace !important;\">using WidgetsUnlimited::ObjectManager;  \nObjectManager mgr;  \nmgr.DoSomething();  \n  \n\n<\/pre>\n<\/p>\n<p style=\"color: rgb(42, 42, 42); margin-bottom: 0px; padding-bottom: 15px; line-height: 18px; font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px;\">Use a using directive to bring everything in the namespace into scope:<\/p>\n<p id=\"code-snippet-4\" class=\"codeSnippetContainer\" xmlns=\"\" style=\"min-width: 0px; clear: both; color: rgb(0, 0, 0); font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 17.55px;\">\n<p class=\"codeSnippetContainerTabs\" style=\"vertical-align: middle; height: 23px; position: relative; z-index: 1;\">\n<p class=\"codeSnippetContainerCodeContainer\" style=\"border: 1px solid rgb(147, 147, 147); clear: both; margin-bottom: 12px; position: relative; top: -1px;\">\n<p class=\"codeSnippetToolBar\" style=\"width: auto; height: auto;\">\n<p class=\"codeSnippetToolBarText\" style=\"float: right; top: -8px; position: relative; width: auto; padding-left: 0px; padding-right: 0px; height: 0px; vertical-align: top; background-color: rgb(255, 255, 255);\">\n<p id=\"CodeSnippetContainerCode_0af39ed4-5672-4c9c-8b9c-32cfcdda2916\" class=\"codeSnippetContainerCode\" dir=\"ltr\" style=\"width: auto; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 10px 21px;\">\n<p style=\"padding: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;\">\n<pre style=\"padding: 5px; margin-top: 0px; margin-bottom: 0px; overflow: auto; word-wrap: normal; font-family: Consolas, Courier, monospace !important;\">using namespace WidgetsUnlimited;  \nObjectManager mgr;  \nmgr.DoSomething();  \nFunc(mgr);  \n  \n\n<\/pre>\n<\/p>\n<p style=\"color: rgb(0, 0, 0); font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 17.55px;\">\n<h2 class=\"LW_CollapsibleArea_TitleDiv\" style=\"font-family: &quot;Segoe UI Semibold&quot;, &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px; font-weight: normal; margin: 0px; padding-bottom: 5px; padding-top: 20px; line-height: 1.3em;\"><a class=\"LW_CollapsibleArea_TitleAhref\" title=\"\" role=\"heading\" style=\"cursor: text; outline: none; color: rgb(0, 114, 198);\"><span class=\"LW_CollapsibleArea_Title\" style=\"display: inline-block; font-family: &quot;Segoe UI Semibold&quot;, &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0); font-size: 1.769em; line-height: 1.3em;\">using directives<\/span><\/a><\/p>\n<p class=\"LW_CollapsibleArea_HrDiv\" style=\"padding-top: 0px;\">\n<\/h2>\n<p class=\"sectionblock\" style=\"padding-left: 15px; padding-bottom: 20px;\"><a id=\"using-directives\" style=\"color: rgb(0, 114, 198);\"><\/a><\/p>\n<p style=\"color: rgb(42, 42, 42); margin-bottom: 0px; padding-bottom: 15px; line-height: 18px; font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px;\">The<span class=\"Apple-converted-space\">&nbsp;<\/span><code>using<\/code><span class=\"Apple-converted-space\">&nbsp;<\/span>directive allows all the names in a<strong>namespace<\/strong><span class=\"Apple-converted-space\">&nbsp;<\/span>to be used without the<span class=\"Apple-converted-space\">&nbsp;<\/span><em>namespace-name<\/em>as an explicit qualifier. Use a using directive in an implementation file (i.e. *.cpp) if you are using several different identifiers in a namespace; if you are just using one or two identifiers, then consider a using declaration to only bring those identifiers into scope and not all the identifiers in the namespace. If a local variable has the same name as a namespace variable, the namespace variable is hidden. It is an error to have a namespace variable with the same name as a global variable.<\/p>\n<p class=\"contentTableWrapper\" style=\"overflow-x: auto; color: rgb(0, 0, 0); font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 17.55px;\">\n<table summary=\"table\" style=\"border-collapse: collapse; margin-bottom: 20px; margin-top: 20px; border: 1px solid rgb(187, 187, 187);\">\n<tbody>\n<tr>\n<th scope=\"col\" style=\"padding: 10px 8px; color: rgb(99, 99, 99); text-align: left; border: 1px solid rgb(187, 187, 187); background-color: rgb(237, 237, 237);\"><img decoding=\"async\" id=\"s-e6f6a65cf14f462597b64ac058dbe1d0-system-media-system-caps-icon-note\" alt=\"System_CAPS_ICON_note.jpg\" src=\"https:\/\/i0.wp.com\/i-msdn.sec.s-msft.com\/dynimg\/IC101471.jpeg?w=750&#038;ssl=1\" title=\"System_CAPS_ICON_note.jpg\" xmlns=\"\" style=\"border: 0px; max-width: none;\" data-recalc-dims=\"1\">&nbsp;<token space=\"preserve\">Note<\/token><\/th>\n<\/tr>\n<tr>\n<td style=\"padding: 10px 8px; color: rgb(42, 42, 42); vertical-align: top; border: 1px solid rgb(187, 187, 187);\">\n<p style=\"margin-bottom: 0px; padding-bottom: 15px; line-height: 18px;\">A using directive can be placed at the top of a .cpp file (at file scope), or inside a class or function definition.<\/p>\n<p style=\"margin-bottom: 0px; padding-bottom: 0px; line-height: 18px;\">In general, avoid putting using directives in header files (*.h) because any file that includes that header will bring everything in the namespace into scope, which can cause name hiding and name collision problems that are very difficult to debug. Always use fully qualified names in a header file. If those names get too long, you can use a namespace alias to shorten them. (See below.)<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"color: rgb(0, 0, 0); font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 17.55px;\">\n<h2 class=\"LW_CollapsibleArea_TitleDiv\" style=\"font-family: &quot;Segoe UI Semibold&quot;, &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px; font-weight: normal; margin: 0px; padding-bottom: 5px; padding-top: 20px; line-height: 1.3em;\"><a class=\"LW_CollapsibleArea_TitleAhref\" title=\"\" role=\"heading\" style=\"cursor: text; outline: none; color: rgb(0, 114, 198);\"><span class=\"LW_CollapsibleArea_Title\" style=\"display: inline-block; font-family: &quot;Segoe UI Semibold&quot;, &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0); font-size: 1.769em; line-height: 1.3em;\">Declaring namespaces and namespace members<\/span><\/a><\/p>\n<p class=\"LW_CollapsibleArea_HrDiv\" style=\"padding-top: 0px;\">\n<\/h2>\n<p class=\"sectionblock\" style=\"padding-left: 15px; padding-bottom: 20px;\"><a id=\"Declaring-namespaces-and-namespace-members\" style=\"color: rgb(0, 114, 198);\"><\/a><\/p>\n<p style=\"color: rgb(42, 42, 42); margin-bottom: 0px; padding-bottom: 15px; line-height: 18px; font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px;\">Typically, you declare a namespace in a header file. If your function implementations are in a separate file, then qualify the function names, as in this example.<\/p>\n<p id=\"code-snippet-5\" class=\"codeSnippetContainer\" xmlns=\"\" style=\"min-width: 0px; clear: both; color: rgb(0, 0, 0); font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 17.55px;\">\n<p class=\"codeSnippetContainerTabs\" style=\"vertical-align: middle; height: 23px; position: relative; z-index: 1;\">\n<p class=\"codeSnippetContainerCodeContainer\" style=\"border: 1px solid rgb(147, 147, 147); clear: both; margin-bottom: 12px; position: relative; top: -1px;\">\n<p class=\"codeSnippetToolBar\" style=\"width: auto; height: auto;\">\n<p class=\"codeSnippetToolBarText\" style=\"float: right; top: -8px; position: relative; width: auto; padding-left: 0px; padding-right: 0px; height: 0px; vertical-align: top; background-color: rgb(255, 255, 255);\">\n<p id=\"CodeSnippetContainerCode_1caa0b43-4539-4097-911a-a6206f8f2961\" class=\"codeSnippetContainerCode\" dir=\"ltr\" style=\"width: auto; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 10px 21px;\">\n<p style=\"padding: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;\">\n<pre style=\"padding: 5px; margin-top: 0px; margin-bottom: 0px; overflow: auto; word-wrap: normal; font-family: Consolas, Courier, monospace !important;\">\/\/contosoData.h   \n#pragma once  \nnamespace ContosoDataServer  \n{  \n    void Foo();  \n    int Bar();  \n  \n}  \n\n<\/pre>\n<\/p>\n<p style=\"color: rgb(42, 42, 42); margin-bottom: 0px; padding-bottom: 15px; line-height: 18px; font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px;\">Function implementations in contosodata.cpp should use the fully qualified name, even if you place a using directive at the top of the file:<\/p>\n<p id=\"code-snippet-6\" class=\"codeSnippetContainer\" xmlns=\"\" style=\"min-width: 0px; clear: both; color: rgb(0, 0, 0); font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 17.55px;\">\n<p class=\"codeSnippetContainerTabs\" style=\"vertical-align: middle; height: 23px; position: relative; z-index: 1;\">\n<p class=\"codeSnippetContainerCodeContainer\" style=\"border: 1px solid rgb(147, 147, 147); clear: both; margin-bottom: 12px; position: relative; top: -1px;\">\n<p class=\"codeSnippetToolBar\" style=\"width: auto; height: auto;\">\n<p class=\"codeSnippetToolBarText\" style=\"float: right; top: -8px; position: relative; width: auto; padding-left: 0px; padding-right: 0px; height: 0px; vertical-align: top; background-color: rgb(255, 255, 255);\">\n<p id=\"CodeSnippetContainerCode_ad9fde63-7d27-4de5-8a6f-a076a4ca1a45\" class=\"codeSnippetContainerCode\" dir=\"ltr\" style=\"width: auto; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 10px 21px;\">\n<p style=\"padding: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;\">\n<pre style=\"padding: 5px; margin-top: 0px; margin-bottom: 0px; overflow: auto; word-wrap: normal; font-family: Consolas, Courier, monospace !important;\">#include \"contosodata.h\"  \nusing namespace ContosoDataServer;   \n  \nvoid ContosoDataServer::Foo()  \n{  \n   \/\/no qualification because using directive above  \n   Bar();   \n}  \n  \nint ContosoDataServer::Bar(){return 0;}  \n\n<\/pre>\n<\/p>\n<p style=\"color: rgb(42, 42, 42); margin-bottom: 0px; padding-bottom: 15px; line-height: 18px; font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px;\">A namespace can be declared in multiple blocks in a single file, and in multiple files. The compiler joins the parts together during preprocessing and the resulting namespace contains all the members declared in all the parts. An example of this is the std namespace which is declared in each of the header files in the standard library.<\/p>\n<p style=\"color: rgb(42, 42, 42); margin-bottom: 0px; padding-bottom: 15px; line-height: 18px; font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px;\">Members of a named namespace can be defined outside the namespace in which they are declared by<a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/84ad8xz9.aspx\" style=\"color: rgb(0, 112, 159);\">explicit qualification<\/a><span class=\"Apple-converted-space\">&nbsp;<\/span>of the name being defined. However, the definition must appear after the point of declaration in a namespace that encloses the declaration&#8217;s namespace. For example:<\/p>\n<p id=\"code-snippet-7\" class=\"codeSnippetContainer\" xmlns=\"\" style=\"min-width: 0px; clear: both; color: rgb(0, 0, 0); font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 17.55px;\">\n<p class=\"codeSnippetContainerTabs\" style=\"vertical-align: middle; height: 23px; position: relative; z-index: 1;\">\n<p class=\"codeSnippetContainerCodeContainer\" style=\"border: 1px solid rgb(147, 147, 147); clear: both; margin-bottom: 12px; position: relative; top: -1px;\">\n<p class=\"codeSnippetToolBar\" style=\"width: auto; height: auto;\">\n<p class=\"codeSnippetToolBarText\" style=\"float: right; top: -8px; position: relative; width: auto; padding-left: 0px; padding-right: 0px; height: 0px; vertical-align: top; background-color: rgb(255, 255, 255);\">\n<p id=\"CodeSnippetContainerCode_cff74dc3-d84f-4671-a998-cad43669df18\" class=\"codeSnippetContainerCode\" dir=\"ltr\" style=\"width: auto; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 10px 21px;\">\n<p style=\"padding: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;\">\n<pre style=\"padding: 5px; margin-top: 0px; margin-bottom: 0px; overflow: auto; word-wrap: normal; font-family: Consolas, Courier, monospace !important;\">\/\/ defining_namespace_members.cpp  \n\/\/ C2039 expected  \nnamespace V {  \n        void f();  \n    }  \n  \n    void V::f() { }        \/\/ ok  \n    void V::g() { }        \/\/ C2039, g() is not yet a member of V  \n  \n    namespace V {  \n        void g();  \n    }  \n}  \n\n<\/pre>\n<\/p>\n<p style=\"color: rgb(42, 42, 42); margin-bottom: 0px; padding-bottom: 15px; line-height: 18px; font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px;\">This error can occur when namespace members are declared across multiple header files, and you have not included those headers in the correct order.<\/p>\n<p style=\"color: rgb(0, 0, 0); font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 17.55px;\">\n<h2 class=\"LW_CollapsibleArea_TitleDiv\" style=\"font-family: &quot;Segoe UI Semibold&quot;, &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px; font-weight: normal; margin: 0px; padding-bottom: 5px; padding-top: 20px; line-height: 1.3em;\"><a class=\"LW_CollapsibleArea_TitleAhref\" title=\"\" role=\"heading\" style=\"cursor: text; outline: none; color: rgb(0, 114, 198);\"><span class=\"LW_CollapsibleArea_Title\" style=\"display: inline-block; font-family: &quot;Segoe UI Semibold&quot;, &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0); font-size: 1.769em; line-height: 1.3em;\">The global namespace<\/span><\/a><\/p>\n<p class=\"LW_CollapsibleArea_HrDiv\" style=\"padding-top: 0px;\">\n<\/h2>\n<p class=\"sectionblock\" style=\"padding-left: 15px; padding-bottom: 20px;\"><a id=\"The-global-namespace\" style=\"color: rgb(0, 114, 198);\"><\/a><\/p>\n<p style=\"color: rgb(42, 42, 42); margin-bottom: 0px; padding-bottom: 15px; line-height: 18px; font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px;\">If an identifier is not declared in an explicit namespace, it is part of the implicit global namespace. In general, try to avoid making declarations at global scope when possible, except for the entry point<span class=\"Apple-converted-space\">&nbsp;<\/span><a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/3ze4ytsc.aspx\" style=\"color: rgb(0, 112, 159);\">main Function<\/a>, which is required to be in the global namespace. To explicitly qualify a global identifier, use the scope resolution operator with no name, as in<span class=\"Apple-converted-space\">&nbsp;<\/span><code>::SomeFunction(x);<\/code>. This will differentiate the identifier from anything with the same name in any other namespace, and it will also help to make your code easier for others to understand.<\/p>\n<p style=\"color: rgb(0, 0, 0); font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 17.55px;\">\n<h2 class=\"LW_CollapsibleArea_TitleDiv\" style=\"font-family: &quot;Segoe UI Semibold&quot;, &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px; font-weight: normal; margin: 0px; padding-bottom: 5px; padding-top: 20px; line-height: 1.3em;\"><a class=\"LW_CollapsibleArea_TitleAhref\" title=\"\" role=\"heading\" style=\"cursor: text; outline: none; color: rgb(0, 114, 198);\"><span class=\"LW_CollapsibleArea_Title\" style=\"display: inline-block; font-family: &quot;Segoe UI Semibold&quot;, &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0); font-size: 1.769em; line-height: 1.3em;\">The std namespace<\/span><\/a><\/p>\n<p class=\"LW_CollapsibleArea_HrDiv\" style=\"padding-top: 0px;\">\n<\/h2>\n<p class=\"sectionblock\" style=\"padding-left: 15px; padding-bottom: 20px;\"><a id=\"The-std-namespace\" style=\"color: rgb(0, 114, 198);\"><\/a><\/p>\n<p style=\"color: rgb(42, 42, 42); margin-bottom: 0px; padding-bottom: 15px; line-height: 18px; font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px;\">All C++ standard library types and functions are declared in the std namespace or namespaces nested inside std.<\/p>\n<p style=\"color: rgb(0, 0, 0); font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 17.55px;\">\n<h2 class=\"LW_CollapsibleArea_TitleDiv\" style=\"font-family: &quot;Segoe UI Semibold&quot;, &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px; font-weight: normal; margin: 0px; padding-bottom: 5px; padding-top: 20px; line-height: 1.3em;\"><a class=\"LW_CollapsibleArea_TitleAhref\" title=\"\" role=\"heading\" style=\"cursor: text; outline: none; color: rgb(0, 114, 198);\"><span class=\"LW_CollapsibleArea_Title\" style=\"display: inline-block; font-family: &quot;Segoe UI Semibold&quot;, &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0); font-size: 1.769em; line-height: 1.3em;\">Nested namespaces<\/span><\/a><\/p>\n<p class=\"LW_CollapsibleArea_HrDiv\" style=\"padding-top: 0px;\">\n<\/h2>\n<p class=\"sectionblock\" style=\"padding-left: 15px; padding-bottom: 20px;\"><a id=\"Nested-namespaces\" style=\"color: rgb(0, 114, 198);\"><\/a><\/p>\n<p style=\"color: rgb(42, 42, 42); margin-bottom: 0px; padding-bottom: 15px; line-height: 18px; font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px;\">Namespaces may be nested. An ordinary nested namespace has unqualified access to its parent\u2019s members, but the parent members do not have unqualified access to the nested namespace (unless it is declared as inline), as shown in the following example:<\/p>\n<p id=\"code-snippet-8\" class=\"codeSnippetContainer\" xmlns=\"\" style=\"min-width: 0px; clear: both; color: rgb(0, 0, 0); font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 17.55px;\">\n<p class=\"codeSnippetContainerTabs\" style=\"vertical-align: middle; height: 23px; position: relative; z-index: 1;\">\n<p class=\"codeSnippetContainerCodeContainer\" style=\"border: 1px solid rgb(147, 147, 147); clear: both; margin-bottom: 12px; position: relative; top: -1px;\">\n<p class=\"codeSnippetToolBar\" style=\"width: auto; height: auto;\">\n<p class=\"codeSnippetToolBarText\" style=\"float: right; top: -8px; position: relative; width: auto; padding-left: 0px; padding-right: 0px; height: 0px; vertical-align: top; background-color: rgb(255, 255, 255);\">\n<p id=\"CodeSnippetContainerCode_0b45fc98-cf69-46cc-ac27-64623414c3b8\" class=\"codeSnippetContainerCode\" dir=\"ltr\" style=\"width: auto; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 10px 21px;\">\n<p style=\"padding: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;\">\n<pre style=\"padding: 5px; margin-top: 0px; margin-bottom: 0px; overflow: auto; word-wrap: normal; font-family: Consolas, Courier, monospace !important;\">namespace ContosoDataServer  \n{  \n    void Foo();   \n  \n    namespace Details  \n    {  \n        int CountImpl;  \n        void Ban() { return Foo(); }  \n    }  \n  \n    int Bar(){...};  \n    int Baz(int i) { return Details::CountImpl; }      \n  \n}  \n\n<\/pre>\n<\/p>\n<p style=\"color: rgb(42, 42, 42); margin-bottom: 0px; padding-bottom: 15px; line-height: 18px; font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px;\">Ordinary nested namespaces can be used to encapsulate internal implementation details that are not part of the public interface of the parent namespace.<\/p>\n<p style=\"color: rgb(0, 0, 0); font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 17.55px;\">\n<h2 class=\"LW_CollapsibleArea_TitleDiv\" style=\"font-family: &quot;Segoe UI Semibold&quot;, &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px; font-weight: normal; margin: 0px; padding-bottom: 5px; padding-top: 20px; line-height: 1.3em;\"><a class=\"LW_CollapsibleArea_TitleAhref\" title=\"\" role=\"heading\" style=\"cursor: text; outline: none; color: rgb(0, 114, 198);\"><span class=\"LW_CollapsibleArea_Title\" style=\"display: inline-block; font-family: &quot;Segoe UI Semibold&quot;, &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0); font-size: 1.769em; line-height: 1.3em;\">Inline namespaces (C++ 11)<\/span><\/a><\/p>\n<p class=\"LW_CollapsibleArea_HrDiv\" style=\"padding-top: 0px;\">\n<\/h2>\n<p class=\"sectionblock\" style=\"padding-left: 15px; padding-bottom: 20px;\"><a id=\"Inline-namespaces-C-11\" style=\"color: rgb(0, 114, 198);\"><\/a><\/p>\n<p style=\"color: rgb(42, 42, 42); margin-bottom: 0px; padding-bottom: 15px; line-height: 18px; font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px;\">In contrast to an ordinary nested namespace, members of an inline namespace are treated as members of the parent namespace. This characteristic enables argument dependent lookup on overloaded functions to work on functions that have overloads in a parent and a nested inline namespace. It also enables you to declare a specialization in a parent namespace for a template that is declared in the inline namespace. The following example shows how external code binds to the inline namespace by default:<\/p>\n<p id=\"code-snippet-9\" class=\"codeSnippetContainer\" xmlns=\"\" style=\"min-width: 0px; clear: both; color: rgb(0, 0, 0); font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 17.55px;\">\n<p class=\"codeSnippetContainerTabs\" style=\"vertical-align: middle; height: 23px; position: relative; z-index: 1;\">\n<p class=\"codeSnippetContainerCodeContainer\" style=\"border: 1px solid rgb(147, 147, 147); clear: both; margin-bottom: 12px; position: relative; top: -1px;\">\n<p class=\"codeSnippetToolBar\" style=\"width: auto; height: auto;\">\n<p class=\"codeSnippetToolBarText\" style=\"float: right; top: -8px; position: relative; width: auto; padding-left: 0px; padding-right: 0px; height: 0px; vertical-align: top; background-color: rgb(255, 255, 255);\">\n<p id=\"CodeSnippetContainerCode_c764aabb-778d-4f14-82d8-5745cf643f87\" class=\"codeSnippetContainerCode\" dir=\"ltr\" style=\"width: auto; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 10px 21px;\">\n<p style=\"padding: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;\">\n<pre style=\"padding: 5px; margin-top: 0px; margin-bottom: 0px; overflow: auto; word-wrap: normal; font-family: Consolas, Courier, monospace !important;\">\/\/Header.h  \n#include &lt;string&gt;  \n  \nnamespace Test  \n{  \n    namespace old_ns  \n    {  \n        std::string Func() { return std::string(\"Hello from old\"); }  \n    }  \n  \n    inline namespace new_ns  \n    {  \n        std::string Func() { return std::string(\"Hello from new\"); }  \n    }  \n}  \n  \n#include \"header.h\"  \n#include &lt;string&gt;  \n#include &lt;iostream&gt;  \n  \nint main()  \n{  \n    using namespace Test;  \n    using namespace std;  \n  \n    string s = Func();  \n    std::cout &lt;&lt; s &lt;&lt; std::endl; \/\/ \"Hello from new\"  \n    return 0;  \n}  \n\n<\/pre>\n<\/p>\n<p style=\"color: rgb(42, 42, 42); margin-bottom: 0px; padding-bottom: 15px; line-height: 18px; font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px;\">The following example shows how you can declare a specialization in a parent of a template that is declared in an inline namespace:<\/p>\n<p id=\"code-snippet-10\" class=\"codeSnippetContainer\" xmlns=\"\" style=\"min-width: 0px; clear: both; color: rgb(0, 0, 0); font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 17.55px;\">\n<p class=\"codeSnippetContainerTabs\" style=\"vertical-align: middle; height: 23px; position: relative; z-index: 1;\">\n<p class=\"codeSnippetContainerCodeContainer\" style=\"border: 1px solid rgb(147, 147, 147); clear: both; margin-bottom: 12px; position: relative; top: -1px;\">\n<p class=\"codeSnippetToolBar\" style=\"width: auto; height: auto;\">\n<p class=\"codeSnippetToolBarText\" style=\"float: right; top: -8px; position: relative; width: auto; padding-left: 0px; padding-right: 0px; height: 0px; vertical-align: top; background-color: rgb(255, 255, 255);\">\n<p id=\"CodeSnippetContainerCode_86c5415d-3e22-4465-9d26-1e617a805111\" class=\"codeSnippetContainerCode\" dir=\"ltr\" style=\"width: auto; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 10px 21px;\">\n<p style=\"padding: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;\">\n<pre style=\"padding: 5px; margin-top: 0px; margin-bottom: 0px; overflow: auto; word-wrap: normal; font-family: Consolas, Courier, monospace !important;\">namespace Parent  \n{  \n    inline namespace new_ns  \n    {  \n         template &lt;typename T&gt;  \n         struct C  \n         {  \n             T member;  \n         };  \n    }  \n     template&lt;&gt;  \n     class C&lt;int&gt; {};  \n}  \n  \n\n<\/pre>\n<\/p>\n<p style=\"color: rgb(42, 42, 42); margin-bottom: 0px; padding-bottom: 15px; line-height: 18px; font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px;\">You can use inline namespaces as a versioning mechanism to manage changes to the public interface of a library. For example, you can create a single parent namespace, and encapsulate each version of the interface in its own namespace nested inside the parent. The namespace that holds the most recent or preferred version is qualified as inline, and is therefore exposed as if it were a direct member of the parent namespace. Client code that invokes the Parent::Class will automatically bind to the new code. Clients that prefer to use the older version can still access it by using the fully qualified path to the nested namespace that has that code.<\/p>\n<p style=\"color: rgb(42, 42, 42); margin-bottom: 0px; padding-bottom: 15px; line-height: 18px; font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px;\">The inline keyword must be applied to the first declaration of the namespace in a compilation unit.<\/p>\n<p style=\"color: rgb(42, 42, 42); margin-bottom: 0px; padding-bottom: 15px; line-height: 18px; font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px;\">The following example shows two versions of an interface, each in a nested namespace. The<span class=\"Apple-converted-space\">&nbsp;<\/span><code>v_20<\/code>namespace has some modification from the<span class=\"Apple-converted-space\">&nbsp;<\/span><code>v_10<\/code>interface and is marked as inline. Client code that uses the new library and calls<code>Contoso::Funcs::Add<\/code><span class=\"Apple-converted-space\">&nbsp;<\/span>will invoke the v_20 version. Code that attempts to call<code>Contoso::Funcs::Divide<\/code><span class=\"Apple-converted-space\">&nbsp;<\/span>will now get a compile time error. If they really need that function, they can still access the<span class=\"Apple-converted-space\">&nbsp;<\/span><code>v_10<\/code><span class=\"Apple-converted-space\">&nbsp;<\/span>version by explicitly calling<code>Contoso::v_10::Funcs::Divide<\/code>.<\/p>\n<p id=\"code-snippet-11\" class=\"codeSnippetContainer\" xmlns=\"\" style=\"min-width: 0px; clear: both; color: rgb(0, 0, 0); font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 17.55px;\">\n<p class=\"codeSnippetContainerTabs\" style=\"vertical-align: middle; height: 23px; position: relative; z-index: 1;\">\n<p class=\"codeSnippetContainerCodeContainer\" style=\"border: 1px solid rgb(147, 147, 147); clear: both; margin-bottom: 12px; position: relative; top: -1px;\">\n<p class=\"codeSnippetToolBar\" style=\"width: auto; height: auto;\">\n<p class=\"codeSnippetToolBarText\" style=\"float: right; top: -8px; position: relative; width: auto; padding-left: 0px; padding-right: 0px; height: 0px; vertical-align: top; background-color: rgb(255, 255, 255);\">\n<p id=\"CodeSnippetContainerCode_cf9c16f4-bdd0-45da-a183-b77a41e69f20\" class=\"codeSnippetContainerCode\" dir=\"ltr\" style=\"width: auto; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 10px 21px;\">\n<p style=\"padding: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;\">\n<pre style=\"padding: 5px; margin-top: 0px; margin-bottom: 0px; overflow: auto; word-wrap: normal; font-family: Consolas, Courier, monospace !important;\">namespace Contoso  \n{  \n    namespace v_10  \n    {  \n        template &lt;typename T&gt;  \n        class Funcs  \n        {  \n        public:  \n            Funcs(void);  \n            T Add(T a, T b);  \n            T Subtract(T a, T b);  \n            T Multiply(T a, T b);  \n            T Divide(T a, T b);  \n        };  \n    }  \n  \n    inline namespace v_20  \n    {  \n        template &lt;typename T&gt;  \n        class Funcs  \n        {  \n        public:  \n            Funcs(void);  \n            T Add(T a, T b);  \n            T Subtract(T a, T b);  \n            T Multiply(T a, T b);  \n            std::vector&lt;double&gt; Log(double);  \n            T Accumulate(std::vector&lt;T&gt; nums);  \n      };  \n    }  \n}  \n  \n\n<\/pre>\n<\/p>\n<p style=\"color: rgb(0, 0, 0); font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 17.55px;\">\n<h2 class=\"LW_CollapsibleArea_TitleDiv\" style=\"font-family: &quot;Segoe UI Semibold&quot;, &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px; font-weight: normal; margin: 0px; padding-bottom: 5px; padding-top: 20px; line-height: 1.3em;\"><a class=\"LW_CollapsibleArea_TitleAhref\" title=\"\" role=\"heading\" style=\"cursor: text; outline: none; color: rgb(0, 114, 198);\"><span class=\"LW_CollapsibleArea_Title\" style=\"display: inline-block; font-family: &quot;Segoe UI Semibold&quot;, &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0); font-size: 1.769em; line-height: 1.3em;\">Namespace aliases<\/span><\/a><\/p>\n<p class=\"LW_CollapsibleArea_HrDiv\" style=\"padding-top: 0px;\">\n<\/h2>\n<p class=\"sectionblock\" style=\"padding-left: 15px; padding-bottom: 20px;\"><a id=\"Namespace-aliases\" style=\"color: rgb(0, 114, 198);\"><\/a><\/p>\n<p style=\"color: rgb(42, 42, 42); margin-bottom: 0px; padding-bottom: 15px; line-height: 18px; font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px;\">Namespace names need to be unique, which means that often they should not be too short. If the length of a name makes code difficult to read, or is tedious to type in a header file where using directives can\u2019t be used, then you can make a namespace alias which serves as an abbreviation for the actual name. For example:<\/p>\n<p id=\"code-snippet-12\" class=\"codeSnippetContainer\" xmlns=\"\" style=\"min-width: 0px; clear: both; color: rgb(0, 0, 0); font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 17.55px;\">\n<p class=\"codeSnippetContainerTabs\" style=\"vertical-align: middle; height: 23px; position: relative; z-index: 1;\">\n<p class=\"codeSnippetContainerCodeContainer\" style=\"border: 1px solid rgb(147, 147, 147); clear: both; margin-bottom: 12px; position: relative; top: -1px;\">\n<p class=\"codeSnippetToolBar\" style=\"width: auto; height: auto;\">\n<p class=\"codeSnippetToolBarText\" style=\"float: right; top: -8px; position: relative; width: auto; padding-left: 0px; padding-right: 0px; height: 0px; vertical-align: top; background-color: rgb(255, 255, 255);\">\n<p id=\"CodeSnippetContainerCode_e552cfc4-b4ee-434b-a172-50ae180ffd44\" class=\"codeSnippetContainerCode\" dir=\"ltr\" style=\"width: auto; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 10px 21px;\">\n<p style=\"padding: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;\">\n<pre style=\"padding: 5px; margin-top: 0px; margin-bottom: 0px; overflow: auto; word-wrap: normal; font-family: Consolas, Courier, monospace !important;\">namespace a_very_long_namespace_name { class Foo {}; }  \nnamespace AVLNN = a_very_long_namespace_name;  \nvoid Bar(AVLNN::Foo foo){ }  \n  \n\n<\/pre>\n<\/p>\n<p style=\"color: rgb(0, 0, 0); font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 17.55px;\">\n<h2 class=\"LW_CollapsibleArea_TitleDiv\" style=\"font-family: &quot;Segoe UI Semibold&quot;, &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px; font-weight: normal; margin: 0px; padding-bottom: 5px; padding-top: 20px; line-height: 1.3em;\"><a class=\"LW_CollapsibleArea_TitleAhref\" title=\"\" role=\"heading\" style=\"cursor: text; outline: none; color: rgb(0, 114, 198);\"><span class=\"LW_CollapsibleArea_Title\" style=\"display: inline-block; font-family: &quot;Segoe UI Semibold&quot;, &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0); font-size: 1.769em; line-height: 1.3em;\">anonymous or unnamed namespaces<\/span><\/a><\/p>\n<p class=\"LW_CollapsibleArea_HrDiv\" style=\"padding-top: 0px;\">\n<\/h2>\n<p class=\"sectionblock\" style=\"padding-left: 15px; padding-bottom: 20px;\"><a id=\"anonymous-or-unnamed-namespaces\" style=\"color: rgb(0, 114, 198);\"><\/a><\/p>\n<p style=\"color: rgb(42, 42, 42); margin-bottom: 0px; padding-bottom: 15px; line-height: 18px; font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px;\">You can create an explicit namespace but not give it a name:<\/p>\n<p id=\"code-snippet-13\" class=\"codeSnippetContainer\" xmlns=\"\" style=\"min-width: 0px; clear: both; color: rgb(0, 0, 0); font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 17.55px;\">\n<p class=\"codeSnippetContainerTabs\" style=\"vertical-align: middle; height: 23px; position: relative; z-index: 1;\">\n<p class=\"codeSnippetContainerCodeContainer\" style=\"border: 1px solid rgb(147, 147, 147); clear: both; margin-bottom: 12px; position: relative; top: -1px;\">\n<p class=\"codeSnippetToolBar\" style=\"width: auto; height: auto;\">\n<p class=\"codeSnippetToolBarText\" style=\"float: right; top: -8px; position: relative; width: auto; padding-left: 0px; padding-right: 0px; height: 0px; vertical-align: top; background-color: rgb(255, 255, 255);\">\n<p id=\"CodeSnippetContainerCode_2e28ccf4-9675-45b8-b8d4-a71ccb157451\" class=\"codeSnippetContainerCode\" dir=\"ltr\" style=\"width: auto; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 10px 21px;\">\n<p style=\"padding: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;\">\n<pre style=\"padding: 5px; margin-top: 0px; margin-bottom: 0px; overflow: auto; word-wrap: normal; font-family: Consolas, Courier, monospace !important;\">namespace  \n{  \n    int MyFunc(){}  \n}  \n\n<\/pre>\n<\/p>\n<p style=\"color: rgb(42, 42, 42); margin-bottom: 0px; padding-bottom: 15px; line-height: 18px; font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px;\">This is called an unnamed or anonymous namespace and it is useful when you want to make variable declarations invisible to code in other files (i.e. give them internal linkage) without having to create a named namespace. All code in the same file can see the identifiers in an unnamed namespace but the identifiers, along with the namespace itself, are not visible outside that file\u2014or more precisely outside the translation unit.<\/p>\n<\/blockquote>\n<p>Source: https<a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/5cb46ksf.aspx\">:\/\/msdn.microsoft.com\/en-us\/library\/5cb46ksf.aspx<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The latest version of this topic can be found atNamespaces (C++). A namespace is a declarative region that provides a scope to the identifiers (the names of types, functions, variables, etc) inside it. Namespaces are used to organize code into<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"quote","meta":{"_mi_skip_tracking":false},"categories":[30,1,215],"tags":[48,690,689],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p8jhJx-fh","_links":{"self":[{"href":"https:\/\/rosetta.vn\/short\/wp-json\/wp\/v2\/posts\/947"}],"collection":[{"href":"https:\/\/rosetta.vn\/short\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rosetta.vn\/short\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rosetta.vn\/short\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/rosetta.vn\/short\/wp-json\/wp\/v2\/comments?post=947"}],"version-history":[{"count":0,"href":"https:\/\/rosetta.vn\/short\/wp-json\/wp\/v2\/posts\/947\/revisions"}],"wp:attachment":[{"href":"https:\/\/rosetta.vn\/short\/wp-json\/wp\/v2\/media?parent=947"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rosetta.vn\/short\/wp-json\/wp\/v2\/categories?post=947"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rosetta.vn\/short\/wp-json\/wp\/v2\/tags?post=947"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}