<p>In C++, what is the purpose of the scope resolution operator when used without a scope? For instance:</p>

<pre><code>::foo();
</code></pre>

[{'answer_id': 75224, 'author': 'shoosh', 'author_id': 9611, 'author_profile': 'https://Stackoverflow.com/users/9611', 'pm_score': 2, 'selected': False, 'text': '<p>referring to the global scope</p>\n'}, {'answer_id': 75249, 'author': 'Drealmer', 'author_id': 12291, 'author_profile': 'https://Stackoverflow.com/users/12291', 'pm_score': 2, 'selected': False, 'text': '<p>When you already have a function named foo() in your local scope but you need to access the one in the global scope.</p>\n'}, {'answer_id': 75251, 'author': 'itsmatt', 'author_id': 7862, 'author_profile': 'https://Stackoverflow.com/users/7862', 'pm_score': 2, 'selected': False, 'text': '<p>My c++ is rusty but I believe if you have a function declared in the local scope, such as foo() and one at global scope, foo() refers to the local one. ::foo() will refer to the global one.</p>\n'}, {'answer_id': 75262, 'author': 'Mark', 'author_id': 4405, 'author_profile': 'https://Stackoverflow.com/users/4405', 'pm_score': 7, 'selected': True, 'text': '<p>It means global scope.  You might need to use this operator when you have conflicting functions or variables in the same scope and you need to use a global one.  You might have something like:</p>\n\n<pre><code>void bar();    // this is a global function\n\nclass foo {\n    void some_func() { ::bar(); }    // this function is calling the global bar() and not the class version\n    void bar();                      // this is a class member\n};\n</code></pre>\n\n<p>If you need to call the global bar() function from within a class member function, you should use ::bar() to get to the global version of the function.</p>\n'}, {'answer_id': 75309, 'author': 'Matt Price', 'author_id': 852, 'author_profile': 'https://Stackoverflow.com/users/852', 'pm_score': 3, 'selected': False, 'text': "<p>Also you should note, that name resolution happens before overload resolution. So if there is something with the same name in your current scope then it will stop looking for other names and try to use them.</p>\n\n<pre><code>void bar() {};\nclass foo {\n    void bar(int) {};\n    void foobar() { bar(); } // won't compile needs ::bar()\n    void foobar(int i) { bar(i); } // ok\n}\n</code></pre>\n"}, {'answer_id': 22085788, 'author': 'Shafik Yaghmour', 'author_id': 1708801, 'author_profile': 'https://Stackoverflow.com/users/1708801', 'pm_score': 4, 'selected': False, 'text': '<p>A name that begins with the <a href="http://en.wikipedia.org/wiki/Scope_resolution_operator" rel="noreferrer">scope resolution operator </a>(<code>::</code>) is looked up in the global namespace. We can see this by looking at the <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3485.pdf" rel="noreferrer">draft C++ standard</a> section <code>3.4.3</code> <em>Qualified name lookup</em> paragraph <em>4</em> which says (<em>emphasis mine</em>):</p>\n\n<blockquote>\n  <p>A name prefixed by the unary scope operator :: (5.1) <strong>is looked up in global scope</strong>, in the translation unit where it is used. The name shall be declared in global namespace scope or shall be a name whose declaration is visible in global scope because of a using-directive (3.4.3.2). The use of :: <strong>allows a global name to be referred to even if its identifier has been hidden</strong> (3.3.10).</p>\n</blockquote>\n\n<p>As the standard states this allows us to use names from the global namespace <a href="http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8l.doc%2Flanguage%2Fref%2Fcplr175.htm" rel="noreferrer">that would otherwise be hidden</a>, the example from the linked document is as follows:</p>\n\n<pre><code>int count = 0;\n\nint main(void) {\n  int count = 0;\n  ::count = 1;  // set global count to 1\n  count = 2;    // set local count to 2\n  return 0;\n}\n</code></pre>\n\n<p>The wording is very similar going back to <a href="http://www.open-std.org/Jtc1/sc22/wg21/docs/papers/2005/n1804.pdf" rel="noreferrer">N1804</a> which is the earliest draft standard available. </p>\n'}]
['https://Stackoverflow.com/questions/75213', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1785/']