PDA

View Full Version : Accessing anonymous namespaces?



maverick_pol
13th April 2008, 23:01
Hi guys,

I have this chunk of code:


...
int x = 10; // global

void main() {
int x = 20; (line A)
{
int x = 30;
// How to read the value of x from the line A in this scope?
}
}

The question is in the code: How to read the value of x from the line A in this scope?


cout << x ; // gives 30;
cout<<::x; // give 10;

Thanks for any help :)

Kacper

marcel
13th April 2008, 23:05
You can't. The local scope overrides the function scope.

maverick_pol
13th April 2008, 23:51
Hi,


The local scope overrides the function scope.

I do know that. But are you 100% sure that the var from the function scope can't be accessed?

Thanks,

Kacper

marcel
14th April 2008, 06:22
Yes, I am sure. :)