c++ - Using qualified name in the global scope -


i've written following code:

#include <iostream>  namespace {     int z=::b; }  int b=5;  int main() {     std::cout << a::z; } 

and expected worked correctly. because:

a name prefixed unary scope operator :: (5.1) looked in global scope, in translation unit used. name shall declared in global namespace scope or shall name declaration visible in global scope because of using-directive (3.4.3.2). use of :: allows global name referred if identifier has been hidden (3.3.10).

this quote said nothing variable must declare lexically before using of qualified id.

the name shall declared in global namespace scope

you have write:

int b=5;  namespace {     int z=::b; } 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -