Env indexing

what "::var" good for?
is that good for direct index to the global env?
then is this faster when I use in a deep local place?

1
2
3
4
5
6
7
8
9
10
11
12
13

#include<stdio.h>

const char*hue="hue";

int main(){
  {{{{{{{{{{
    int var2(1);
    puts(::hue);
  }}}}}}}}}}
  return 0;
};
"::var" simply specifies that you want to use the "var" that is in the global namespace, rather than any entity with the same name in a different namespace. Consider:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

int var = 10;   // Global variable

namespace myNameSpace
{
int var = 5;
}

namespace myNameSpace
{

int main()
{
  std::cout << ::var << std::endl;  // Outputs "10"
  std::cout << myNameSpace::var << std::endl;  // Outputs "5"
  std::cout << var << std::endl;  // COMPILER ERROR - var is ambiguous
}

}


I don't think there's any performance improvement using ::var - it simply disambiguates the name.
hmm I guessed well in my mind...
thanks
Topic archived. No new replies allowed.