{"id":32780,"date":"2021-04-30T20:06:47","date_gmt":"2021-04-30T14:36:47","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/namespaces-in-cpp\/"},"modified":"2024-11-13T16:23:20","modified_gmt":"2024-11-13T10:53:20","slug":"namespaces-in-cpp","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/namespaces-in-cpp\/","title":{"rendered":"Introduction to Namespace in C++"},"content":{"rendered":"\n<p>Think about a circumstance when we have two people with a similar name, Zara, in a similar class. At whatever point we need to separate them, we would need to utilize some extra data alongside their name, as either the territory, if they live in various regions or their mom's or father's name, and so forth.&nbsp;<\/p>\n\n\n\n<p>The same circumstance can emerge in your C++ applications. For instance, you may be thinking of some code that has a capacity called xyz(), and there is another library accessible which is likewise having the same capacity xyz(). Presently the compiler has no chance to know which variant of xyz() work you are alluding to inside your code.&nbsp;<\/p>\n\n\n\n<p>A namespace is intended to beat this trouble. It is utilized as extra data to separate comparative capacities, classes, factors, and a similar name accessible in various libraries. Using namespace, you can characterize the setting where names are characterized. A namespace characterizes a degree.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"definition\"><strong>Definition:<\/strong><\/h2>\n\n\n\n<p>Namespaces permit us to bunch named elements that in any case would have a worldwide degree into smaller extensions, giving them namespace scope. This permits putting together the components of projects into various consistent extensions alluded to by names.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Namespace is a component included C++ and not present in C.\u00a0<\/li>\n\n\n\n<li>A namespace is a revelatory district that gives a degree to the identifiers (names of the kinds, work, factors and so forth) inside it.\u00a0<\/li>\n\n\n\n<li>Various namespace blocks with a similar name are permitted. All presentations inside those squares are proclaimed in the named scope.<\/li>\n\n\n\n<li>Namespaces in C++ are utilized to coordinate such a large number of classes with the goal that it tends to be not difficult to deal with the application.\u00a0<\/li>\n\n\n\n<li>For getting to the class of a namespace, we need to utilize namespacename::classname. We can utilize catchphrases with the goal that we don't need to utilize total names constantly.\u00a0<\/li>\n\n\n\n<li>In C++, worldwide namespace is the root namespace. The global::std will consistently allude to the namespace \"sexually transmitted disease\" of C++ Framework.<\/li>\n<\/ul>\n\n\n\n<p>A namespace definition starts with the catchphrase namespace followed by the namespace name as follows:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nnamespace namespace_name \n{\n   int x, y; \/\/ code declarations where \n             \/\/ x and y are declared in \n             \/\/ namespace_name&#039;s scope\n}\n\n<\/pre><\/div>\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Academy Pro<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/learn-c-programming-for-beginners-to-advanced\" class=\"courses-cta-title-link\">C++ Programming Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">Master key C++ programming concepts like variables, functions, OOP, and control structures. Build real-world projects such as a banking system and grade management tool.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>Beginner to Advanced Level<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>8.1 hrs<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/learn-c-programming-for-beginners-to-advanced\" class=\"courses-cta-button\">\n                Start Free Trial\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"using-directives\"><strong>Using directives:<\/strong><\/h2>\n\n\n\n<p>The using directive permits every one of the names in a namespace to be used without the namespace-name as an explicit qualifier. Utilize a using directive in an execution document (for example *.cpp) on the off chance that you are utilizing a few unique identifiers in a namespace; assuming you are simply utilizing a couple of identifiers, consider a using-declaration to just bring those identifiers into the scope and not every one of the identifiers in the namespace. On the off chance that a nearby factor has a similar name as a namespace variable, the namespace variable is covered up. It is an error to have a namespace variable with a similar name as a global variable.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"the-global-namespace\"><strong>The Global Namespace:<\/strong><\/h2>\n\n\n\n<p>On the off chance that an identifier isn't pronounced in an unequivocal namespace, it is important for the implied worldwide namespace. By and large, attempt not to make revelations at a worldwide degree whenever the situation allows, aside from the section point primary Function, which is needed in the worldwide namespace. To expressly qualify a worldwide identifier, utilize the degree goal administrator with no name, as in::SomeFunction(x);. This will separate the identifier from anything with a similar name in some other namespace, and it will likewise assist with making your code simpler for others to comprehend.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"declaring-namespaces-and-namespace-members\"><strong>Declaring namespaces and namespace members:<\/strong><\/h2>\n\n\n\n<p>Ordinarily, you pronounce a namespace in a header record. On the off chance that your capacity executions are in a different record, qualify the capacity names, as in this model.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\/\/contosoData.h\n#pragma once\nnamespace ContosoDataServer\n{\n    void Foo();\n    int Bar();\n}\n\n<\/pre><\/div>\n\n\n<p>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\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n#include &quot;contosodata.h&quot;\nusing namespace ContosoDataServer;\n\nvoid ContosoDataServer::Foo() \/\/ use fully-qualified name here\n{\n   \/\/ no qualification needed for Bar()\n   Bar();\n}\n\nint ContosoDataServer::Bar(){return 0;}\n\n\n<\/pre><\/div>\n\n\n<p>A namespace can be announced in different squares in a solitary document and various records. The compiler consolidates the parts during preprocessing, and the subsequent namespace contains every one of the individuals pronounced the parts altogether. An illustration of this is the sexually transmitted disease namespace announced in every one of the header records in the standard library.&nbsp;<\/p>\n\n\n\n<p>Individuals from a named namespace can be characterized outside the namespace in which they are proclaimed by the express capability of the name being characterized. Nonetheless, the definition should show up after the mark of presentation in a namespace that encases the affirmation's namespace. For instance:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\/\/ defining_namespace_members.cpp\n\/\/ C2039 expected\nnamespace V {\n    void f();\n}\n\nvoid V::f() { }        \/\/ ok\nvoid V::g() { }        \/\/ C2039, g() is not yet a member of V\n\nnamespace V {\n    void g();\n}\n\n<\/pre><\/div>\n\n\n<p>This error can occur when the namespace members are declared across multiple header files, and you have not included those headers in the correct order.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"the-std-namespace\"><strong>The std Namespace:<\/strong><\/h2>\n\n\n\n<p>All C++ standard library types and functions are declared in the std namespace or namespaces nested inside std.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"creation\"><strong>Creation:<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Namespace declarations show up just at worldwide degrees.\u00a0<\/li>\n\n\n\n<li>Namespace declaration can be settled inside another namespace.\u00a0<\/li>\n\n\n\n<li>Namespace declarations don't approach specifiers. (Public or private)\u00a0<\/li>\n\n\n\n<li>No compelling reason to give semicolon after the end support of the meaning of namespace.\u00a0<\/li>\n\n\n\n<li>We can part the meaning of a namespace with more than a few units.<\/li>\n<\/ul>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\/\/ Creating namespaces\n#include &amp;lt;iostream&gt;\nusing namespace std;\nnamespace ns1\n{\n    int value()    { return 5; }\n}\nnamespace ns2 \n{\n    const double x = 100;\n    double value() {  return 2*x; }\n}\n  \nint main()\n{\n    \/\/ Access value function within ns1\n    cout &amp;lt;&amp;lt; ns1::value() &amp;lt;&amp;lt; &#039;\\n&#039;; \n  \n    \/\/ Access value function within ns2\ncout &amp;lt;&amp;lt; ns2::value() &amp;lt;&amp;lt; &#039;\\n&#039;; \n  \n    \/\/ Access variable x directly\n    cout &amp;lt;&amp;lt; ns2::x &amp;lt;&amp;lt; &#039;\\n&#039;;       \n  \n    return 0;\n}\n\n\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<p>5<\/p>\n\n\n\n<p>200<\/p>\n\n\n\n<p>100<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"nested-namespaces\"><strong>Nested Namespaces:<\/strong><\/h2>\n\n\n\n<p>Namespaces can be settled where you can characterize one namespace inside another name space as follows \u2013<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nnamespace namespace_name1 {\n   \/\/ code declarations\n   namespace namespace_name2 {\n      \/\/ code declarations\n   }\n}\n\n\n<\/pre><\/div>\n\n\n<p>You can get to individuals from settled namespace by the use of resolution operators as follows \u2013<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\/\/ to access members of namespace_name2\nusing namespace namespace_name1::namespace_name2;\n\n\/\/ to access members of namespace:name1\nusing namespace namespace_name1;\n\n\n<\/pre><\/div>\n\n\n<p>In the above articulations assuming you are using namespace_name1, it will make components of namespace_name2 accessible in the scope as follows \u2013<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n#include &amp;lt;iostream&gt;\nusing namespace std;\n\n\/\/ first name space\nnamespace first_space {\n   void func() {\n      cout &amp;lt;&amp;lt; &quot;Inside first_space&quot; &amp;lt;&amp;lt; endl;\n   }\n   \n   \/\/ second name space\n   namespace second_space {\n      void func() {\n         cout &amp;lt;&amp;lt; &quot;Inside second_space&quot; &amp;lt;&amp;lt; endl;\n      }\n   }\n}\n\nusing namespace first_space::second_space;\nint main () {\n   \/\/ This calls function from second name space.\n   func();\n   \n   return 0;\n}\n\n<\/pre><\/div>\n\n\n<p>If we compile and run above code, this would produce the following result \u2013<\/p>\n\n\n\n<p>Inside second_space<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"inline-namespaces\"><strong>Inline Namespaces:<\/strong><\/h2>\n\n\n\n<p>Rather than a common settled namespace, individuals from an inline namespace are treated as individuals from the parent namespace. This trademark empowers subordinate contention queries on over-burden capacities to chip away at capacities with over-burdens in a parent and a settled inline namespace. It additionally empowers you to proclaim a specialization in a parent namespace for a layout that is pronounced in the inline namespace. The accompanying model shows how outer code ties to the inline namespace naturally:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\/\/Header.h\n#include &amp;lt;string&gt;\n\nnamespace Test\n{\n    namespace old_ns\n    {\n        std::string Func() { return std::string(&quot;Hello from old&quot;); }\n    }\n\n    inline namespace new_ns\n    {\n        std::string Func() { return std::string(&quot;Hello from new&quot;); }\n    }\n}\n\n#include &quot;header.h&quot;\n#include &amp;lt;string&gt;\n#include &amp;lt;iostream&gt;\n\nint main()\n{\n    using namespace Test;\n    using namespace std;\n\n    string s = Func();\n    std::cout &amp;lt;&amp;lt; s &amp;lt;&amp;lt; std::endl; \/\/ &quot;Hello from new&quot;\n    return 0;\n}\n\n<\/pre><\/div>\n\n\n<p>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\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nnamespace Parent\n{\n    inline namespace new_ns\n    {\n         template &amp;lt;typename T&gt;\n         struct C\n         {\n             T member;\n         };\n    }\n     template&amp;lt;&gt;\n     class C&amp;lt;int&gt; {};\n}\n\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"namespace-aliases\"><strong>Namespace aliases:<\/strong><\/h2>\n\n\n\n<p>You can utilize inline namespaces as a forming component to oversee changes to the public interface. For instance, you can make a solitary parent namespace and epitomize every form of the interface in its namespace settled inside the parent. The namespace that holds the latest or favoured adaptation is qualified as inline and is accordingly uncovered as an immediate individual from the parent namespace. Customer code that conjures the Parent::Class will consequently tie to the new code. Customers that like to utilize the more seasoned variant can, in any case, get to it by utilizing the completely qualified way to the settled namespace that has that code.&nbsp;<\/p>\n\n\n\n<p>The accompanying model shows two variants of an interface, each in a settled namespace. The v_20 namespace has some adjustment from the v_10 interface and is set apart as inline. Customer code that utilizes the new library and calls Contoso::Funcs::Add will summon the v_20 variant. Code that endeavors to call Contoso::Funcs::Divide will currently get an assemble time blunder. On the off chance that they truly need that work, they can in any case get to the v_10 form by unequivocally calling Contoso::v_10::Funcs::Divide.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nnamespace Contoso\n{\n    namespace v_10\n    {\n        template &amp;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 &amp;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&amp;lt;double&gt; Log(double);\n            T Accumulate(std::vector&amp;lt;T&gt; nums);\n      };\n    }\n}\n\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"anonymous-or-unnamed-namespaces\"><strong>Anonymous or unnamed namespaces:<\/strong><\/h2>\n\n\n\n<p>You can create an explicit namespace but not give it a name:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nnamespace\n{\n    int MyFunc(){}\n}\n\n<\/pre><\/div>\n\n\n<p>This is called an anonymous or unknown namespace. It is valuable to make variable affirmations imperceptible to code in different records (for example, give them inside linkage) without making a named namespace. All code in a similar record can see the identifiers in an anonymous namespace. Yet, the identifiers, alongside the namespace itself, are not noticeable outside that document\u2014or all the more unequivocally outside the interpretation unit.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"scope-resolution-operator\"><strong>Scope resolution operator (::):<\/strong><\/h2>\n\n\n\n<p>We can explicitly specify any name declared in a namespace using the namespace\u2019s name and the scope resolution \u201c<strong>::\u201d<\/strong> operator with the identifier.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nnamespace New_space\n{\n    class X\n    {\n        static int i;\n        public:\n        void func();\n    };\n     \n    \/\/ class name declaration\n    class Y;    \n     \n}\n \n\/\/ Initializing static class variable\nint New_space::X::i=23;      \n \nclass New_space::Y\n{\n    int a;\n    public:\n    int getdata()\n    {\n        cout &amp;lt;&amp;lt; a;\n    }\n    \/\/ Constructor declaration\n    Y();   \n}\n \n\/\/ Constructor definition explicitly\nNew_space::Y::Y()   \n{\n    a=0;\n}\n\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"discontiguous-namespace-in-c\"><strong>Discontiguous Namespace in C++:<\/strong><\/h2>\n\n\n\n<p>As we probably know, a namespace in C++ can be characterized in a few sections; hence it consists of the amount of its independently characterized parts. Thus, if one piece of the namespace requires a name characterized in another document, that name should, in any case, be announced in its extension. Composing the accompanying namespace in an accompanying way either characterizes another namespace or adds new components to a current one:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"advantages\"><strong>Advantages:<\/strong><\/h2>\n\n\n\n<p>The standard library contains the basic usefulness you use in building your applications like holders, calculations, and so on. On the off chance that names utilized by these were out in the open, for instance, if they characterized a line class around the world, you'd always be unable to utilize a similar name again without clashes. So they made a namespace, sexually transmitted disease to contain this change.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"disadvantages\"><strong>Disadvantages:<\/strong><\/h2>\n\n\n\n<p>Calls to functions can be ambiguous if they are defined in more than one place.<br>To disambiguate, we use the prefix NameOfNamespace:: before the function. This is less risky when using multiple libraries.<\/p>\n\n\n\n<p>This brings us to the end of the blog on Namespaces in C++. We hope that you were able to gain comprehensive knowledge about Namespaces in C++. If you wish to learn more such concepts in programming, do check out <a href=\"https:\/\/www.mygreatlearning.com\/academy\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Great Learning Academy's Free Online Courses<\/strong><\/a> and upskill today. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Think about a circumstance when we have two people with a similar name, Zara, in a similar class. At whatever point we need to separate them, we would need to utilize some extra data alongside their name, as either the territory, if they live in various regions or their mom's or father's name, and so [&hellip;]<\/p>\n","protected":false},"author":41,"featured_media":32789,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25860],"tags":[36801],"content_type":[],"class_list":["post-32780","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","tag-c-programming"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.6 (Yoast SEO v27.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Namespaces in C++ | What does Namespaces in C++ Mean?<\/title>\n<meta name=\"description\" content=\"Namespaces in C++ are utilized to coordinate such a large number of classes with the goal that it tends to be not difficult to deal with the application.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/namespaces-in-cpp\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Introduction to Namespace in C++\" \/>\n<meta property=\"og:description\" content=\"Namespaces in C++ are utilized to coordinate such a large number of classes with the goal that it tends to be not difficult to deal with the application.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/namespaces-in-cpp\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-04-30T14:36:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-13T10:53:20+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-512275675.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1174\" \/>\n\t<meta property=\"og:image:height\" content=\"893\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.mygreatlearning.com\/blog\/namespaces-in-cpp\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.mygreatlearning.com\/blog\/namespaces-in-cpp\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"Introduction to Namespace in C++\",\"datePublished\":\"2021-04-30T14:36:47+00:00\",\"dateModified\":\"2024-11-13T10:53:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.mygreatlearning.com\/blog\/namespaces-in-cpp\/\"},\"wordCount\":1566,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.mygreatlearning.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.mygreatlearning.com\/blog\/namespaces-in-cpp\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-512275675.jpg\",\"keywords\":[\"C++ Programming\"],\"articleSection\":[\"IT\/Software Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.mygreatlearning.com\/blog\/namespaces-in-cpp\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.mygreatlearning.com\/blog\/namespaces-in-cpp\/\",\"url\":\"https:\/\/www.mygreatlearning.com\/blog\/namespaces-in-cpp\/\",\"name\":\"Namespaces in C++ | What does Namespaces in C++ Mean?\",\"isPartOf\":{\"@id\":\"https:\/\/www.mygreatlearning.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.mygreatlearning.com\/blog\/namespaces-in-cpp\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.mygreatlearning.com\/blog\/namespaces-in-cpp\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-512275675.jpg\",\"datePublished\":\"2021-04-30T14:36:47+00:00\",\"dateModified\":\"2024-11-13T10:53:20+00:00\",\"description\":\"Namespaces in C++ are utilized to coordinate such a large number of classes with the goal that it tends to be not difficult to deal with the application.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.mygreatlearning.com\/blog\/namespaces-in-cpp\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.mygreatlearning.com\/blog\/namespaces-in-cpp\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.mygreatlearning.com\/blog\/namespaces-in-cpp\/#primaryimage\",\"url\":\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-512275675.jpg\",\"contentUrl\":\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-512275675.jpg\",\"width\":1174,\"height\":893,\"caption\":\"Namespaces in C++\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.mygreatlearning.com\/blog\/namespaces-in-cpp\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\/\/www.mygreatlearning.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"IT\/Software Development\",\"item\":\"https:\/\/www.mygreatlearning.com\/blog\/software\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Introduction to Namespace in C++\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.mygreatlearning.com\/blog\/#website\",\"url\":\"https:\/\/www.mygreatlearning.com\/blog\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\/\/www.mygreatlearning.com\/blog\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.mygreatlearning.com\/blog\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\/\/www.mygreatlearning.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg\",\"contentUrl\":\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\",\"https:\/\/x.com\/Great_Learning\",\"https:\/\/www.instagram.com\/greatlearningofficial\/\",\"https:\/\/www.linkedin.com\/school\/great-learning\/\",\"https:\/\/in.pinterest.com\/greatlearning12\/\",\"https:\/\/www.youtube.com\/user\/beaconelearning\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp\",\"contentUrl\":\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\/\/www.mygreatlearning.com\/\",\"https:\/\/in.linkedin.com\/school\/great-learning\/\",\"https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning\",\"https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Namespaces in C++ | What does Namespaces in C++ Mean?","description":"Namespaces in C++ are utilized to coordinate such a large number of classes with the goal that it tends to be not difficult to deal with the application.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mygreatlearning.com\/blog\/namespaces-in-cpp\/","og_locale":"en_US","og_type":"article","og_title":"Introduction to Namespace in C++","og_description":"Namespaces in C++ are utilized to coordinate such a large number of classes with the goal that it tends to be not difficult to deal with the application.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/namespaces-in-cpp\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2021-04-30T14:36:47+00:00","article_modified_time":"2024-11-13T10:53:20+00:00","og_image":[{"width":1174,"height":893,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-512275675.jpg","type":"image\/jpeg"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/namespaces-in-cpp\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/namespaces-in-cpp\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"Introduction to Namespace in C++","datePublished":"2021-04-30T14:36:47+00:00","dateModified":"2024-11-13T10:53:20+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/namespaces-in-cpp\/"},"wordCount":1566,"commentCount":0,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/namespaces-in-cpp\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-512275675.jpg","keywords":["C++ Programming"],"articleSection":["IT\/Software Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.mygreatlearning.com\/blog\/namespaces-in-cpp\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/namespaces-in-cpp\/","url":"https:\/\/www.mygreatlearning.com\/blog\/namespaces-in-cpp\/","name":"Namespaces in C++ | What does Namespaces in C++ Mean?","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/namespaces-in-cpp\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/namespaces-in-cpp\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-512275675.jpg","datePublished":"2021-04-30T14:36:47+00:00","dateModified":"2024-11-13T10:53:20+00:00","description":"Namespaces in C++ are utilized to coordinate such a large number of classes with the goal that it tends to be not difficult to deal with the application.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/namespaces-in-cpp\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/namespaces-in-cpp\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/namespaces-in-cpp\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-512275675.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-512275675.jpg","width":1174,"height":893,"caption":"Namespaces in C++"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/namespaces-in-cpp\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"IT\/Software Development","item":"https:\/\/www.mygreatlearning.com\/blog\/software\/"},{"@type":"ListItem","position":3,"name":"Introduction to Namespace in C++"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-512275675.jpg",1174,893,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-512275675-150x150.jpg",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-512275675-300x228.jpg",300,228,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-512275675-768x584.jpg",768,584,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-512275675-1024x779.jpg",1024,779,true],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-512275675.jpg",1174,893,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-512275675.jpg",1174,893,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-512275675-640x853.jpg",640,853,true],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-512275675-96x96.jpg",96,96,true],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-512275675-150x114.jpg",150,114,true]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"Think about a circumstance when we have two people with a similar name, Zara, in a similar class. At whatever point we need to separate them, we would need to utilize some extra data alongside their name, as either the territory, if they live in various regions or their mom's or father's name, and so&hellip;","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/32780","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=32780"}],"version-history":[{"count":12,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/32780\/revisions"}],"predecessor-version":[{"id":110701,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/32780\/revisions\/110701"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/32789"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=32780"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=32780"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=32780"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=32780"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}