scope of a variable

hi

int main ()
{
int a =10;
{
int a = ::a; // this is giving error how to fix this??
a =20
cout<<"a :"<<a<<endl; this should print a = 20;
cout<<"A : "<<::a<<endl; this chould print A =10;
}
}

How to achive this??

i used c++ and g++ compiler...

what is happening ???

thanks
You can't do that. Inner "a" declaration shadows outer "a" declaration. There is
no way in this case to tell the compiler which "a" you want; it will assume the inner
one in the inner block.
Topic archived. No new replies allowed.