Look at this piece of code
int x = 1;
int main(int argc, char* argv[])
{
int x = 2;
{
int x = 3;
cout << x << endl;
cout << ::x;
}
getch();
return 0;
}
When i call x from within the block i'm getting 3. When i call ::x i'm getting 1. Is it possible to call x equal to 2 from within the block?
With cheating:
int x = 1;
int main(int argc, char* argv[])
{
int x = 2;
{
int& ox = x;
int x = 3;
cout << x << endl;
cout << ::x << endl;
cout << ox << endl;
}
getch();
return 0;
}
No, it's not possible to do that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With